課程
/后端開發(fā)
/Python
/Python開發(fā)簡單爬蟲
這個是執(zhí)行的結果,不知道為什么有問題,應該是編碼問題,有沒有大神指教一下
2020-05-21
源自:Python開發(fā)簡單爬蟲 5-3
正在回答
cj = http.cookiejar.CookieJar()opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))urllib.request.install_opener(opener)response3 = urllib.request.urlopen(url)print(response3.getcode())print(cj)print(len(response3.read()))
import?urllib.request from?http?import?cookiejar url='https://www.baidu.com/' print('第一種方法') response1=urllib.request.urlopen(url) print(response1.getcode()) print(len(response1.read())) print('第二種方法') request?=?urllib.request.Request(url) request.add_header('user-agent',"Mozilla/5.0") response2=urllib.request.urlopen(request) print(response2.getcode()) print(len(response2.read())) print('第三種方法') cookie=cookiejar.CookieJar() cj=cookie opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) urllib.request.install_opener(opener) response3=urllib.request.urlopen(request) print(response3.getcode()) print(cj) print(response3.read())
舉報
本教程帶您解開python爬蟲這門神奇技術的面紗
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學習伙伴
掃描二維碼關注慕課網(wǎng)微信公眾號
2020-07-03
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
urllib.request.install_opener(opener)
response3 = urllib.request.urlopen(url)
print(response3.getcode())
print(cj)
print(len(response3.read()))
2020-05-21