GuessedAtParserWarning: No parser was explicitly specified, so I‘m using the best available HTML pa
发布日期:2021-06-30 08:07:29 浏览次数:3 分类:技术文章

本文共 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

转载地址:https://huxiaomu.blog.csdn.net/article/details/116161044 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:python 爬虫(起点)网络小说
下一篇:UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe6 in position 0: ordinal not in range(128)

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月14日 10时47分20秒