栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python爬虫问题-BeautifulSoup库运行提示GuessedAtParserWarning: No parser was explicitly specified

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python爬虫问题-BeautifulSoup库运行提示GuessedAtParserWarning: No parser was explicitly specified

目录
  • 开发工具
  • 问题描述
  • 问题代码
  • 运行结果
  • 解决方案
  • 运行效果
  • 总结

开发工具
  1. python版本: python-3.8.1-amd64
  2. python开发工具: JetBrains PyCharm 2018.3.6 x64
  3. 安装BeautifulSoup库(指定阿里镜像安装会很快)
    pip install beautifulsoup4 -i http://mirrors.aliyun.com/pypi/simple/
问题描述

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.

问题代码
from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen("https://www.baidu.com/s?wd=python%E7%88%AC%E8%99%AB%E4%B9%A6%E7%B1%8D")
bsObj = BeautifulSoup(html.read())
print(bsObj.head)
运行结果
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 5 of the file To get rid of this warning, pass the additional argument 'features="html.parser"' to the BeautifulSoup constructor.

  bsObj = BeautifulSoup(html.read())




解决方案
from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen("https://www.baidu.com/s?wd=python%E7%88%AC%E8%99%AB%E4%B9%A6%E7%B1%8D")
# 在调用的BeautifulSoup指定html.parser即可
bsObj = BeautifulSoup(html.read(), 'html.parser')
print(bsObj.head)
运行效果



总结

提示信息:未明确指定解析器,因此我正在为此系统使用最佳的HTML解析器(“ html.parser”),在调用BeautifulSoup指定html.parser即可

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/619013.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号