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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

python爬蟲(chóng)偽裝瀏覽器出現(xiàn)問(wèn)題求助

python爬蟲(chóng)偽裝瀏覽器出現(xiàn)問(wèn)題求助

22with33 2017-12-03 11:20:26
運(yùn)行報(bào)錯(cuò):: '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貢獻(xiàn)1038條經(jīng)驗(yàn) 獲得超227個(gè)贊

這么明顯的錯(cuò)誤13行,headers必須是一個(gè)字典對(duì)象,你卻給它個(gè)字符串,字符串對(duì)象顯而易見(jiàn)沒(méi)有items方法?。?!str' object has no attribute 'items'

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

查看完整回答
2 反對(duì) 回復(fù) 2017-12-03
  • 1 回答
  • 0 關(guān)注
  • 3158 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)