python中bs4库的安装问题
return super(HTMLParserTreeBuilder, self).__init__(*args, **kwargs)TypeError: __init__() got an unexpected keyword argument 'strict'
安装完成之后 跑了一下课后习题的代码 结果显示这样 该如何解决 你的代码是怎么样的。。。。。。。。。。? import urllib.request
import re
from bs4 import BeautifulSoup
def main():
url = "http://baike.baidu.com/view/284853.htm"
response = urllib.request.urlopen(url)
html = response.read()
soup = BeautifulSoup(html, "html.parser") # 使用 Python 默认的解析器
for each in soup.find_all(href=re.compile("view")):
print(each.text, "->", ''.join(["http://baike.baidu.com", each["href"]]))
# 上边用 join() 不用 + 直接拼接,是因为 join() 被证明执行效率要高很多
if __name__ == "__main__":
main()
然后就报错
Traceback (most recent call last):
File "C:/Users/fzz/AppData/Local/Programs/Python/Python36/BS4练习.py", line 16, in <module>
main()
File "C:/Users/fzz/AppData/Local/Programs/Python/Python36/BS4练习.py", line 9, in main
soup = BeautifulSoup(html, "html.parser") # 使用 Python 默认的解析器
File "C:\Users\fzz\AppData\Local\Programs\Python\Python36\lib\site-packages\bs4\__init__.py", line 153, in __init__
builder = builder_class()
File "C:\Users\fzz\AppData\Local\Programs\Python\Python36\lib\site-packages\bs4\builder\_htmlparser.py", line 49, in __init__
return super(HTMLParserTreeBuilder, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'strict'
C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\python.exe D:/python/test/test02.py
恐龙百科 -> http://baike.baidu.com/wikicategory/view?categoryName=恐龙大全
多肉百科 -> http://baike.baidu.com/wikicategory/view?categoryName=多肉植物
锁定 -> http://baike.baidu.com/view/10812319.htm
Process finished with exit code 0
就是用的你的代码,我这运行正常 看你这报错信息,好像解析器的问题,要么直接换lxml解析
页:
[1]