課程
/后端開發(fā)
/Python
/Python開發(fā)簡單爬蟲
有沒有視頻中demo代碼可以下載的?
2020-02-16
源自:Python開發(fā)簡單爬蟲 1-1
正在回答
from?urllib?import?request from?http?import?cookiejar url?=?"http://www.baidu.com" def?print_response(resp): ????print(resp.code) ????print(len(resp.read())) ????#?第一種方法 print("第一種方法") req?=?request.build_opener() print_response(req.open(url)) #?第二種方法 print("第二種方法") req?=?request.build_opener() req.addheaders.append({"user-agent",?"Mozilla/5.0"}) print_response(req.open(url)) #?第三種方法 print("第三種方法") cj?=?cookiejar.CookieJar() req?=?request.build_opener(request.HTTPCookieProcessor(cj)) print_response(req.open(url)) print(cj)
基于python3的,跟視頻的版本不一樣
舉報
本教程帶您解開python爬蟲這門神奇技術(shù)的面紗
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2020-02-16
基于python3的,跟視頻的版本不一樣