博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
GuessedAtParserWarning: No parser was explicitly specified, so I‘m using the best available HTML pa
阅读量:1946 次
发布时间:2019-04-27

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

你可能感兴趣的文章
Linux下修改^M换行符
查看>>
笔记-有关于Vim
查看>>
vnc, vncserver, ssh的locale问题
查看>>
[野路数] Django中使用logging
查看>>
[未修订]ROS学习笔记
查看>>
Eigen学习笔记
查看>>
PyTorch的学习笔记01-基础中的基础
查看>>
onshape 做参考面等虚拟几何的装配和原点定位
查看>>
MySQL自动补全
查看>>
ANSYS Workbench 输出APDL文件(Input File)到服务器上求解,PBS脚本
查看>>
JAVA学习笔记1 - 类和变量类型
查看>>
JAVA学习笔记2 - 变量类型与修饰符
查看>>
JAVA学习笔记3 - 运算符
查看>>
JAVA学习笔记4 - 循环与分支结构
查看>>
JAVA学习笔记5 - Number类,Math类,Character类,String类,StringBuffer类
查看>>
JAVA学习笔记6 - 数组
查看>>
JAVA学习笔记7 - 方法
查看>>
JAVA学习笔记8 - Stream 和 File I/O
查看>>
JAVA学习笔记9 - 异常
查看>>
JAVA学习笔记10 - 继承
查看>>