爬虫问题解决:UserWarning: No parser was explicitly specified,

版权声明:本文为博主stromztt原创文章,未经博主允许不得转载。如需转载,请私信联系我。 https://blog.csdn.net/weixin_40824913/article/details/89278026

代码:

# -*- encoding: utf-8 -*-
"""
@project = Pa_chong
@file = test2
@auther = ztt
@create_time = '2019/4/13 9:17'
"""
from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen("http://www.pythonscraping.com/pages/warandpeace.html")
bsObj = BeautifulSoup(html)
nameList = bsObj.find_all("span", {"class": "green"})
for name in nameList:
	print(name.get_text())

运行后报警告:

在这里插入图片描述

原因:

  • 需要html5lib库的支持

解决:

  • 安装: pip install html5lib
  • bsObj = BeautifulSoup(html)更改为bsObj = BeautifulSoup(html, "html5lib")

猜你喜欢

转载自blog.csdn.net/weixin_40824913/article/details/89278026