課程
/后端開發
/Python
/Python開發簡單爬蟲
運行結果剛開始的時候還跟老師的一樣,幾秒后前面幾行就消失了?
2018-06-21
源自:Python開發簡單爬蟲 5-3
正在回答
我的也是這樣,哥們你怎么解決的??
# coding:utf8
import cookielib
print '第一種方法'
import urllib2
url= "http://www.baidu.com"
response = urllib2.urlopen(url)
print response.getcode()
cont = len(response.read())
print cont
print '第二種方法'
request = urllib2.Request(url)
request.add_header("user-agent", "Mozilla/5.0")
response2 = urllib2.urlopen(request)
print response2.getcode()
cont = len(response2.read())
print "第三種方法"
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
response3 = urllib2.urlopen(url)
print response3.getcode()
print response3.read()
print cj
舉報
本教程帶您解開python爬蟲這門神奇技術的面紗
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2019-07-24
我的也是這樣,哥們你怎么解決的??
2018-06-22
# coding:utf8
import cookielib
print '第一種方法'
import urllib2
url= "http://www.baidu.com"
response = urllib2.urlopen(url)
print response.getcode()
cont = len(response.read())
print cont
print '第二種方法'
request = urllib2.Request(url)
request.add_header("user-agent", "Mozilla/5.0")
response2 = urllib2.urlopen(request)
print response2.getcode()
cont = len(response2.read())
print cont
print "第三種方法"
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
response3 = urllib2.urlopen(url)
print response3.getcode()
print response3.read()
print cj