python爬虫之BeautifulSoup初始运行时警告

 时间:2024-10-12 14:04:09

1、Python在进行网页爬虫时,代码如下:from urllib.request import urlopen from bs4 import BeautifulSoup html = urlopen("http://www.pythonscraping.com/pages/page1.html") bsObj = BeautifulSoup(html) print (bsObj.h1) nameList = bsObj.findAll(text='the prince') print(len(nameList))

python爬虫之BeautifulSoup初始运行时警告

2、在运行代码时出现了一个用户警告,如下:UserWarning: No parser was explicitly specified, so I'm us足毂忍珩ing the best available HTML parser for this system ("lxml"). 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.0

python爬虫之BeautifulSoup初始运行时警告

3、紧接着是因此此警告的原因,初始化时,未加上解析器亿姣灵秀类型The code that caused this warning is on line 4 of the file C:/Users/15057/PycharmProjects/Stock/Stockinvest/test.py. To get rid of this warning, change code that looks like this:BeautifulSoup(YOUR_MARKUP})to this:BeautifulSoup(YOUR_MARKUP, "lxml") markup_type=markup_type)

python爬虫之BeautifulSoup初始运行时警告

4、详细情况如图所示:

python爬虫之BeautifulSoup初始运行时警告

5、将代码bsObj = BeautifulSoup(html.read())改为bsObj = BeautifulSoup(html.read(),"lxml")就不会报错了

python爬虫之BeautifulSoup初始运行时警告
  • 如何创建一个win32 HelloWorld入门程序
  • 如何在VS2013中新建WindowsService定时任务
  • VS2019如何在Basic显示错误
  • 如何让Qt串口发送ASCII
  • 热门搜索
    好玩的网页游戏大全 古钱币大全 游戏情侣名字大全 河蟹怎么吃 我是你姐啊你怎么这么对我 马斯克简介 手机壁纸图片大全 小熊电器怎么样 动物声音叫声大全 韩国化妆品品牌大全