当我尝试抓取网络数据时出现以下错误:模块 'html5lib.treebuilders' 没有属性 '_base'

The following error pops when I try to scrape web data : module 'html5lib.treebuilders' has no attribute '_base'

我正在 python 中使用 beautiful soup 尝试网络抓取,作为新手,我从 [https://syntaxbytetutorials.com/beautifulsoup-4-python-web-scraping-to-csv-excel-file/] 获取了源代码并开始试验。 现在,我有一个错误

module 'html5lib.treebuilders' has no attribute '_base'`

如果有人向我解释错误背后的原因并提供解决方案,那将非常有帮助 :)

import urllib.request as urllib
import csv
import re
from bs4 import BeautifulSoup
 
rank_page = 'https://socialblade.com/youtube/top/50/mostviewed'
request = urllib.Request(rank_page, headers={'User-Agent':'Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36'})
page = urllib.urlopen(request)
soup = BeautifulSoup(page, 'html.parser')
 
channels = soup.find('div', attrs={'style': 'float: right; width: 900px;'}).find_all('div', recursive=False)[4:]
 
file = open('topyoutubers.csv', 'wb')
writer = csv.writer(file)
 
# write title row
writer.writerow(['Username', 'Uploads', 'Views'])
 
for channel in channels:
    username = channel.find('div', attrs={'style': 'float: left; width: 350px; line-height: 25px;'}).a.text.strip()
    uploads = channel.find('div', attrs={'style': 'float: left; width: 80px;'}).span.text.strip()
    views = channel.find_all('div', attrs={'style': 'float: left; width: 150px;'})[1].span.text.strip()
 
    print (username + ' ' + uploads + ' ' + views)
    writer.writerow([username.encode('utf-8'), uploads.encode('utf-8'), views.encode('utf-8')])
 
file.close()

尝试用“_html5lib.py”中的“base”替换字符串“_base”。

你能显示错误的回溯吗?错误来自哪一行或文件。