您好,登錄后才能下訂單哦!
from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.pythonscraping.com/pages/page1.html")
bsObj = BeautifulSoup(html.read())
print(bsObj.h2)
代碼運行之后警告如下:
UserWarning: No parser was explicitly specified, so I'm using 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.
The code that caused this warning is on line 4 of the file D:/Python/venv/test8.py. To get rid of this warning, pass the additional argument 'features="lxml"' to the BeautifulSoup constructor.
翻譯如下:
用戶警告:沒有顯式指定語法分析器,因此我使用了此系統的最佳可用HTML語法分析器(“lxml”)。這通常不是問題,但是如果您在另一個系統上運行此代碼,或者在不同的虛擬環境中運行此代碼,它可能會使用不同的解析器并表現出不同的行為。
導致此警告的代碼位于文件d:/python/venv/test8.py的第4行。要消除此警告,請將附加參數'features=“lxml”'傳遞給beautifulsoup構造函數。
解決:指定解析器,一般使用'lxml'
from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.pythonscraping.com/pages/page1.html")
bsObj = BeautifulSoup(html.read(),'lxml')
print(bsObj.h2)
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。