【发布时间】:2021-12-15 04:04:47
【问题描述】:
我正在使用 Beautiful Soup 抓取维基百科表格 这是我的代码
代码
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 和 get_text 函数仍然得到同样的错误,即使 th 也出现同样的错误。
【问题讨论】:
标签: python pandas beautifulsoup