我当时是网scraping使用 Beautiful Soup 的 Wikipedia 表
这是我的代码
Code
URL="https://en.wikipedia.org/wiki/List_of_most-viewed_YouTube_videos"
page=requests.get(URL)
soup1=BeautifulSoup(page.text,'lxml')
table = soup1.find('table',{'class':'wikitable sortable jquery-tablesorter'})
headers=[]
for i in table.find_all('tr'):
title=i.text.strip()
headers.append(title)
我得到错误为
AttributeError: 'NoneType' object has no attribute 'find_all'
我尝试使用htmlparser
and get_text
函数仍然出现相同的错误,即使是相同的错误th
also.
你可以只使用 pandas 来做到这一点
import pandas as pd
table = pd.read_html("https://en.wikipedia.org/wiki/List_of_most-viewed_YouTube_videos",attrs={'class':'wikitable sortable'})[0]
print(table)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)