爬蟲問題解決:UserWarning: No parser was explicitly specified,

代碼:

# -*- 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")
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章