最贊回答 / zjxjwxk
看了下面的評論解決了:fout.write("<td>%s</td>" % data['title'].encode('utf-8'))fout.write("<td>%s</td>" % data['summary'].encode('utf-8'))這兩句不需要encode('utf-8'),加了這個title和summary就變成十六進(jìn)制顯示的字符了。需要在這一句fout = open('output.html', 'w', encoding='utf...
2018-03-19
最新回答 / 歐陽思月
import urllib.request導(dǎo)入urllib中的request模塊, 才能調(diào)里面的方法url = ('https://www.baidu.com')surl = urllib.request.urlopen(url)?print(surl.read())
2018-03-17
最新回答 / 幕布斯9454072
試一下這個看? ?:使用pip升級? ?在管理員權(quán)限下使用命令行輸入命令“pip install --upgrade beautifulsoup4”
2018-03-16
最贊回答 / YouAreFoolish
import?urllib.request import?http.cookiejar url?=?'http://www.baidu.com' print('第一種方法') response1?=?urllib.request.urlopen(url) print(response1.getcode()) print(len(response1.read())) print("第二種方法") request?=?urllib.requ...
2018-03-16
最新回答 / 慕萊塢2274375
urllib2.urlopen()方法對于有的鏈接會超時(shí),可以加個異常判斷,跳過這一條。具體可看https://github.com/lzcdev/BaiDuBaiKeSpider
2018-03-13
最新回答 / YunPeng
使用requests吧,urllib感覺不是方便,requests文檔地址:http://docs.python-requests.org/zh_CN/latest/user/quickstart.html
2018-03-07