【发布时间】:2019-09-03 10:08:15
【问题描述】:
我正在关注一个在线教程 (https://www.analyticsvidhya.com/blog/2015/10/beginner-guide-web-scraping-beautiful-soup-python/),用于网页抓取 html 表格。当我按照教程进行操作时,我能够抓取表格数据,但是当我尝试从这个 (https://www.masslottery.com/games/lottery/search/results-history.html?game_id=15&mode=2&selected_date=2019-03-04&x=12&y=11) 网站抓取数据时,我无法这样做。
我之前尝试过使用scrapy,但得到了相同的结果。
这是我使用的代码。
import urllib.request
wiki = "https://www.masslottery.com/games/lottery/search/results-history.html?game_id=15&mode=2&selected_date=2019-03-04&x=12&y=11"
page = urllib.request.urlopen(wiki)
from bs4 import BeautifulSoup
soup = BeautifulSoup(page, "lxml")
all_tables=soup.find_all('table')
right_table=soup.find('table', class_='zebra-body-only')
print(right_table)
这是我在终端上运行此代码时得到的结果
<table cellspacing="0" class="zebra-body-only">
<tbody id="target-area">
</tbody>
</table>
虽然当我使用谷歌浏览器检查大众彩票网站时,这就是我所看到的
<table cellspacing="0" class="zebra-body-only" <tbody id="target-area">
<tr class="odd">
<th>Draw #</th>
<th>Draw Date</th>
<th>Winning Number</th>
<th>Bonus</th>
</tr>
<tr><td>2107238</td>
<td>03/04/2019</td>
<td>01-04-05-16-23-24-27-32-34-41-42-44-47-49-52-55-63-65-67-78</td><td>No Bonus</td>
</tr>
<tr class="odd">
<td>2107239</td>
<td>03/04/2019</td>
<td>04-05-11-15-19-20-23-24-25-28-41-45-52-63-64-68-71-72-73-76</td><td>4x</td>
</tr>
....(And so on)
我希望能够从这个表中提取数据。
【问题讨论】:
标签: python html web-scraping html-table beautifulsoup