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

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

req.add_header問題

# -*- coding:utf-8 -*-

from urllib import request

req=request.urlopen("https://www.baidu.com/")

req.add_header("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36")

resp=request.urlopen(req)

print(resp.read().decode('utf-8'))

報錯

req.add_header("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36")

AttributeError: 'HTTPResponse' object has no attribute 'add_header'


正在回答

1 回答

找到了

req=request.Request("https://www.baidu.com/")寫錯了。。。。

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

舉報

0/150
提交
取消
python遇見數據采集
  • 參與學習       59663    人
  • 解答問題       209    個

本教程讓你初步掌握Python進行數據采集,創造屬于你的價值

進入課程

req.add_header問題

我要回答 關注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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