代码如下:
import requests
import bs4
response = requests.get('http://www.baidu.com')
response.raise_for_status()
noStarchSoup = bs4.BeautifulSoup(response.text)
print(type(noStarchSoup))
运行脚本出现Warning:
GuessedAtParserWarning: No parser was explicitly specified, so I’m using the best available HTML parser for this system (“lxml”). This usually isn’t a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.
The code that caused this warning is on line 10 of the file C:\Users\admin\PycharmProjects\pythonProject\梁.py. To get rid of this warning, pass the additional argument ‘features=“lxml”’ to the BeautifulSoup constructor.
noStarchSoup = bs4.BeautifulSoup(response.text)
根据提示添加参数如下
import requests
import bs4
response = requests.get('http://www.baidu.com')
response.raise_for_status()
# noStarchSoup = bs4.BeautifulSoup(response.text)
noStarchSoup = bs4.BeautifulSoup(response.text, features='lxml')
print(type(noStarchSoup))
再次运行脚本,不再出现warning。