第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

python爬蟲偽裝瀏覽器出現問題求助

python爬蟲偽裝瀏覽器出現問題求助

22with33 2017-12-03 11:20:26
運行報錯:: 'str' object has no attribute 'items'#-*-coding:utf-8?-*- import?urllib.request def?saveFile(data): ????path?=?"E:\\123\\douban.out" ????f?=?open(path,"wb") ????f.write(data) ????f.close() ? url?=?"http://www.douban.com/" headers?=?("User-Agent:?Mozilla/5.0?(Windows?NT?10.0;?Win64;?x64)?AppleWebKit/537.36?(KHTML,?like?Gecko)\ Chrome/58.0.3029.110?Safari/537.36?Edge/16.16299") req?=?urllib.request.Request(url=url,headers=headers) res?=?urllib.request.urlopen(req) data?=?res.read() saveFile(data) data?-?data.decode("utf-8") print(data) print(type(res)) print(res.geturl()) print(res.info()) print(res.getcode())Traceback?(most?recent?call?last): ??File?"E:\抓取首圖.py",?line?13,?in?<module> ????req?=?urllib.request.Request(url=url,headers=headers) ??File?"C:\Users\w1553\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py",?line?335,?in?__init__ ????for?key,?value?in?headers.items(): AttributeError:?'str'?object?has?no?attribute?'items'
查看完整描述

1 回答

已采納
?
pardon110

TA貢獻1038條經驗 獲得超227個贊

這么明顯的錯誤13行,headers必須是一個字典對象,你卻給它個字符串,字符串對象顯而易見沒有items方法?。。tr' object has no attribute 'items'

建議檢查第10行headers的賦值。

查看完整回答
2 反對 回復 2017-12-03
  • 1 回答
  • 0 關注
  • 3147 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號

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