from urllib.request import urlopenfrom bs4 import BeautifulSouphtml=urlopen("http://idcbgp.cn/")object1=BeautifulSoup(html.read())print(object1.h1)運(yùn)行后結(jié)果什么都沒有是怎么回事?等待大神指點(diǎn)??!
1 回答

奇風(fēng)
TA貢獻(xiàn)6條經(jīng)驗 獲得超0個贊
data?=?urlopen(url) data為bytes類型,需要decode()解碼,轉(zhuǎn)換成str類型
推薦使用requests包,Requests 會自動解碼來自服務(wù)器的內(nèi)容。大多數(shù) unicode 字符集都能被無縫地解碼。
添加回答
舉報
0/150
提交
取消