本文共 1459 字,大约阅读时间需要 4 分钟。
python 爬虫提示如下
GuessedAtParserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). 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\PycharmProjects\pythonProject\pa\main.py. To get rid of this warning, pass the additional argument 'features="html.parser"' to the BeautifulSoup constructor.
bs_obj = BeautifulSoup(req_html)
大致意思是:GuessedAtParserWarning:未明确指定解析器,因此我正在为此系统使用最佳的HTML解析器(“ html.parser”)
我大代码是这样的
import requestsfrom bs4 import BeautifulSoupdef getContent(): url = "https://read.qidian.com/chapter/tlBx1lEZoo3djrstIrF5-w2/-hwjPfM_yFT6ItTi_ILQ7A2" req_url = requests.get(url) req_html = req_url.text bs_obj = BeautifulSoup(req_html) texts = bs_obj.find_all("div", class_="read-content j_readContent") print(texts)if __name__ == "__main__": getContent()
处理方法就是添加html.parser
效果如下
import requestsfrom bs4 import BeautifulSoupdef getContent(): url = "https://read.qidian.com/chapter/tlBx1lEZoo3djrstIrF5-w2/-hwjPfM_yFT6ItTi_ILQ7A2" req_url = requests.get(url) req_html = req_url.text bs_obj = BeautifulSoup(req_html, "html.parser") texts = bs_obj.find_all("div", class_="read-content j_readContent") print(texts)if __name__ == "__main__": getContent()
运行ok
转载地址:http://orfif.baihongyu.com/