2014-02-21 63 views
0

我有麻煩從html表中提取數據。我有以下Python代碼,但它給了我一個錯誤信息:使用BeautifulSoup從html表中獲取數據

File "request_test.py", line 50 print(soup.find_all("td", class="station tqdetail top")) ^SyntaxError: invalid syntax

from bs4 import BeautifulSoup 

html_doc = """ 
<html> 
<body> 

<table> 
<tr> 
<th colspan="2">an</th> 
<th>Halt</th> 
<tr> 
<td class="arrival tqdetail"> 
17:24 
<br /> 
17:24 
</td> 
<td class="tqdetail rt top"> 
<span class="okmsg bold">+0</span> 
<br /> 
<span class="okmsg bold">+0</span> 
</td> 
<td class="station tqdetail top"> 
Foo 
<br /> 
</td> 
</tr> 

</body> 
</html> 
""" 

soup = BeautifulSoup(html_doc) 

print(soup.find_all("td", class="station tqdetail top")) 

我不明白我做錯了什麼在這裏,我在這裏欣賞任何線索。

回答

0

在這裏你可以如何使用classsoup

print(soup.find_all("td", {"class":"station tqdetail top"})) 
相關問題