1. 程式人生 > >《python 網絡數據采集》代碼更新

《python 網絡數據采集》代碼更新

req 根據 跟著 pen spec color another spa specified

《python 網絡數據采集》這本書中會出現很多這一段代碼:

1 from urllib.request import urlopen
2 from bs4 import BeautifulSoup
3 html = urlopen(url)
4 bsobj = BeautifulSoup(html)

我也跟著輸入這一段代碼,但會出現提示:

UserWarning: 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 1 of the file <string>. To get rid of this warning, change code that looks like this:

BeautifulSoup(YOUR_MARKUP})

to this:

BeautifulSoup(YOUR_MARKUP, "html.parser")

根據提示,這要把 bsobj = BeautifulSoup(html),改為bsobj = BeautifulSoup(html,"html.parser")就行了。

《python 網絡數據采集》代碼更新