亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

這是最后輸出的結果,請教怎么解決?。?/h1>

第一種方法

200

118011

第二種方法

Traceback (most recent call last):

? File "C:\Users\admin\eclipse-workspace\imoocc\src\test\test1.py", line 16, in <module>

? ? request.add_header("User-agent","Mozilla/5.0")

AttributeError: addinfourl instance has no attribute 'add_header'

從第二種方法就運行不出來啦,請教怎么解決??? 用的python2.7版本


下面是我的代碼

#coding=utf-8

import urllib2

import cookielib


url = "http://www.baidu.com"



print '第一種方法'

response1= urllib2.urlopen(url)

print response1.getcode()

print len(response1.read())



print "第二種方法"

request = urllib2.urlopen(url)

request.add_header("User-agent","Mozilla/5.0")

response2= urllib2.urlopen(url)

print response2.getcode()

print 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 len(response3.read())

print cj

print response3.read()


正在回答

2 回答

print "第二種方法"

request = urllib2.urlopen(url)

#應該是:request = urllib2.Request(url)

1 回復 有任何疑惑可以回復我~

?把你的代碼貼出來,別個才能幫你看啊

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Python開發簡單爬蟲
  • 參與學習       227596    人
  • 解答問題       1288    個

本教程帶您解開python爬蟲這門神奇技術的面紗

進入課程

這是最后輸出的結果,請教怎么解決?。?/h1> 我要回答 關注問題

微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號