import requests
from bs4 import BeautifulSoup
res = requests.get("https://en.wikipedia.org/wiki/Comparison_of_Intel_processors")
soup = BeautifulSoup(res.text, 'lxml') #if you find any problem with "lxml" then try using "html.parser" instead
table = soup.find("table",class_="wikitable")
for items in table.find_all("tr")[:-1]:
data = [' '.join(item.text.split()) for item in items.find_all(['th','td'])]
print(data)
在对列进行排序之前,导航网站时不会出现表类
wikitable sortable jquery-tablesorter
。通过使用table类wikitable sortable
,我只获得了一个表。在注意事项:
class_=
而不是字典,因为standford.edu tutorial on Beautiful Soup。在BeautifulSoup
类中定义了一个名为html.parser
的解析器,因此代码可以按照打印的警告在不同的环境下工作。在试试下面的方法。它将从该网站获取表格数据:
部分输出:
^{pr2}$相关问题 更多 >
编程相关推荐