getting data from html table with BeautifulSoup
从HTML表中提取数据时遇到问题。我有以下python代码,但它给了我一条错误消息:
File"request_test.py", line 50
print(soup.find_all("td", class="station tqdetail top"))
^ SyntaxError: invalid syntax
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 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")) |
我不知道我做错了什么,我很欣赏这里的任何线索。
下面介绍如何在
1 | print(soup.find_all("td", {"class":"station tqdetail top"})) |