【发布时间】:2020-08-14 06:50:17
【问题描述】:
我是 Python 新手,正在使用 BeautifulSoup 练习网页抓取。
我检查了一些类似的问题,例如this one、this one 和this one。但是,我仍然陷入我的问题。
这是我的代码:
import urllib.request
from bs4 import BeautifulSoup
html = urllib.request.urlopen("https://en.wikipedia.org/wiki/List_of_largest_recorded_music_markets").read()
soup = BeautifulSoup(html, 'html.parser')
tbody = soup.find_all('table',{"class":"wikitable plainrowheaders sortable jquery-tablesorter"})
首先,我不认为我正在寻找的网页包含类似问题中提到的 java 脚本。我打算提取这些表中的数据,但是当我执行 print(tbody) 时,我发现它是一个空列表。有人可以看看并给我一些提示吗?
谢谢。
【问题讨论】:
-
jquery-tablesorter类看起来像是由 javascript 添加的。从class参数中省略它。 -
我明白了,抱歉我的粗心。顺便说一句,javascript有一个以“j”开头的类是否大致正确?
标签: python web-scraping beautifulsoup