首页 > 解决方案 > 这个 Python plus BeautifulSoup 脚本有什么问题?

问题描述

我正在使用 BeautifulSoup 学习网页抓取。我需要帮助解决此错误。到目前为止,这是我的代码:

from bs4 import BeautifulSoup as soup
from urllib.request import urlopen as uReq
my_url = 'https://www.newegg.com/Video-Cards-Video-Devices/Category/ID-38? 
Tpk=graphics%20card'
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
page_soup = soup(page_html, "html.parser")  

输出:

Traceback (most recent call last):
File "C:\Users\PC\Desktop\new.py", line 9, in <module>
page_soup = soup(page_html, "html.parser")
File "C:\Users\PC\AppData\Local\Programs\Python\Python37-32\lib\site- 
packages\bs4\__init__.py", line 153, in __init__
builder = builder_class()
File "C:\Users\PC\AppData\Local\Programs\Python\Python37-32\lib\site- 
packages\bs4\builder\_htmlparser.py", line 39, in __init__
return super(HTMLParserTreeBuilder, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'strict'
[Finished in 5.8s with exit code 1]
[cmd: ['C:\\Users\\PC\\AppData\\Local\\Programs\\Python\\Python37- 
32\\python.exe', '-u', 'C:\\Users\\PC\\Desktop\\new.py']]
[dir: C:\Users\PC\Desktop]
[path: C:\Program Files\Common 
Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\C:\;C:\Users\PC\AppData\Local\Programs\Python\Python37-32\Scripts\;C:\Users\PC\AppData\Local\Programs\Python\Python37-32\;C:\Users\PC\DownAPK]

我将不胜感激有关修复此错误的任何帮助...谢谢

标签: pythonbeautifulsoup

解决方案


sudo pip install requests --upgrade

推荐阅读