版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
使?Requests友情提示:?冊(cè)代碼全部基于友情提示:?冊(cè)代碼全部基于Python3.6的實(shí)現(xiàn)代碼。Python提供了?常多?具去實(shí)現(xiàn)HTTP請(qǐng)求,但第三?開(kāi)源庫(kù)提供的功能更豐富,你?需從socket?Pyton內(nèi)建模塊urllib請(qǐng)求?個(gè)URLimportimportfromurllib.requestimportfromurllib.requestimportcontext=HTTPrequestHTTPresponseurlopen(requestcontext=context)headers=()#響應(yīng)頭contentresponse.read(coderesponse.getcode(發(fā)起請(qǐng)求前?先要構(gòu)建請(qǐng)求對(duì)象Request,指定url地址、請(qǐng)求?法、請(qǐng)求頭,這?的請(qǐng)求體data為空,因?yàn)槟悴恍枰峤粩?shù)據(jù)給服務(wù)器,所以你也可以不指定。urlopen函數(shù)會(huì)?動(dòng)與?標(biāo)服務(wù)器建?連接,發(fā)送HTTP請(qǐng)求,該函數(shù)的返回值是?個(gè)響應(yīng)對(duì)象?簡(jiǎn)單爬?可以考慮Requests,Requests 安裝pippipinstallGET>>>>>>r=>>><Response200r.status_coder.content'{\n"origin":POST>>>>>>r=data=AgentReuet經(jīng)常會(huì)指定UA成瀏覽器起請(qǐng)求>>>>>>url='>>>headers={'user-agent':>>>r=requests.get(url,附在URL后?,例如請(qǐng)求url,可使?>>>>>>url=">>>r=requests.get(url,>>> ?部分,我們可以從中剝離出來(lái),使 >>>>>>ss={'from-my':>>>"s":"from-my":可以指定timeout來(lái)設(shè)置請(qǐng)求超時(shí)時(shí)間,單位是秒,超過(guò)該時(shí)間還rr= ',importimportproxies='http':'https':}r=proxies=proxies,/s,那么可以使?session,Session提供的API importimports= sr=s.get('# s":{"a":r=# s":{"a": /pythoneer)Chrome找到獲 現(xiàn)在我們?Requests模擬瀏覽器發(fā)送請(qǐng)求給服務(wù)器,寫(xiě)程序前,我請(qǐng)求 user-agent:Mozilla/5.0(WindowsNT10.0;Win64;AppleWebKit/537.36(KHTML,likeChrome/69.0.3497.100offset:0limit:importimportclassdefcrawl(self,url params={"limit":"offset":0,"data[*].follower_count,gender,is_followed,headers="authority": "user-agent":"Mozilla/5.0(WindowsNT10.0;Win64;x64)"(KHTML,likeGecko)Chrome/63.0.3239.84}response=requests.get(url,headers=headers,params=params)print("請(qǐng)求URL: print("返回?cái)?shù)據(jù):forfollowerinforfollowerinifname=='main 返回?cái)?shù)據(jù):{'paging'{'is_end'Falsetotals':10436,'previous': 'is_start':True,'next': ,'data':[{'is_followed':False, 'user_type':'people','is_following':'headline':'歡 」→城市|理|規(guī)劃|經(jīng)濟(jì)'url_token''joe1324'130894ff204e72b96719a09b5a6565bc','type':'people','name':'','url': 2b96719a09b5a6565bc','gender':1,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':4,'badge':[]},{'is_followed':False, 'user_type':'people','is_following':False,'headline':'','url_token':'hei-tai-yang-91','id':'bbeba0903e14a32d19b27ffa0016ac55','type':'people','name':'JOJO','url': 32d19b27ffa0016ac55','gender':-1,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':4,'badge':[]},{'is_followed':False, 'user_type':'people','is_following':False,'headline':' ','url_token':'wo-zai-xue-xi-ni-87','id':'696dcf2ff66b23ae0ff39474f9f48c5e','type':'people''name'我在學(xué)習(xí)呢 3ae0ff39474f9f48c5e','gender':-'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':0,'badge':[]},{'is_followed':False, 'user_type':'people','is_following':False,'headline':'邏輯?上','url_token':'wang-zhu-yi-65','id':' 'type''people''name'王朮屹 15ee8e8007fbb2419b1','gender':1,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':17,'badge':[]},{'is_followed':False, 194449_{size}.jpg','user_type':'people','is_following'Falseheadline笨?先?'url_token':'wei-sen-ken','people','name':'', 4eee0cde88359e827ff','gender':1,'is_advertiser':False,'avatar_url': 194449_is.jpg','is_org':False,'follower_count':0,'badge':[]}, 'user_type':'people','is_following':False,'headline':'holo','url_token':'zhang-feng-wei','id':'c6ba181c 'type':'people','name':'goingon','url': 256fa71d9ecb8dcdb90','gender':1,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':9,'badge':[]},{'is_followed':False, 'user_type':'people','is_following':'headline'在讀?學(xué)?url_token'fu-53','id':'type':'people','name':'fuPatrick', 3ed369a07ea5cb7553','gender':-1,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':1,'badge':[]},{'is_followed':False, 'user_type':'people','is_following':False,'url_token':'hu-chen-92-42-74','id':'f88db2870e4e9cdbe589b5846fccd70c','type':'people','name':'', cdbe589b5846fccd70c','gender':-1,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':0,'badge':[]},{'is_followed':False, 'user_type':'people','is_following':False,'headline':'','url_token':'zhi-bei-bu-nan','id':'63220b9e8cadb266b236ed0e1d76d1ed','type':'people''name'只北不南 266b236ed0e1d76d1ed','gender':-1,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':0,'badge':[]},{'is_followed':False, 'user_type':'people','is_following':False,'headline':'道路不??條終點(diǎn)不必相同??各?','url_token':'xi-zi-31-56','id':'people','name':'??','url': f4cd73f34398ee21379','gender':1,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':1,'badge':[]},{'is_followed':False, 'user_type':'people','is_following':False,'headline':'Iknownothing.','url_token':'42195','ce5e19c125f8570bee02cdb414f6e233','type':'people','name':'Gladius','url': 70bee02cdb414f6e233','gender':1,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':74,'badge':[]},{'is_followed':False, 'user_type':'people','is_following':False,'url_token':'willbillion','id':'0ee103930c20c21d314a998a371abe82','type':'people','name':'willbillion','url': 21d314a998a371abe82','gender':-1,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':0,'badge':[]},{'is_followed':False, 'user_type':'people','is_following':False,'headline':'','url_token':'yang-guang-xiao-tong','id':'1637b7761fe90da99519d4878a4a991f','type''people''name'陽(yáng)光?桐 da99519d4878a4a991f','gender':0,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':1,'badge':[]},{'is_followed':False, 'user_type':'people','is_following':False,'headline':'Access','url_token':'wang-hua-18-79','id':'d0a5fd983546174636af438651c13018','type':'people','name':'','url': 74636af438651c13018','gender':-'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':0,'badge':[]},{'is_followed':False, ce50d50_{size}.jpg','user_type':'people','is_following':False,'headline':'','url_token':'oriver','id':'cd9bcc01b125999b10d3f19e872601f2','type':'people''name'瑞? 99b10d3f19e872601f2','gender':1,'is_advertiser':False,'avatar_url': ce50d50_is.jpg','is_org':False,'follower_count':28,'badge':[]},{'is_followed':False,'avatar_url_tem 'user_type':'people','is_following':'headline'略。url_token'yuan-yi-ming-75''id''type''people''name'明明就是我 220235bfb92b7fb3774','gender':1,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':10,'badge':[]},{'is_followed':False, 'user_type':'people','is_following':False,'headline'純屬?聊,打發(fā)時(shí)間url_token':'abandon-65-76','id':'e98a2e7d53e048dfc8d8a05e60b361fd','type':'people','name':'Abandon','url': 8dfc8d8a05e60b361fd','gender':-1,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':0,'badge':[]},{'is_followed':False, 'user_type':'people','is_following':'headline'這個(gè)?很懶什么都沒(méi)留下url_token':'10-07-zhihu-er','id':'people','name':'10點(diǎn)睡7點(diǎn)起','url': 45849f4f8ea760ef05','gender':1,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':15,'badge':[]},{'is_followed':False, 'user_type':'people','is_following':False,'headline':'','url_token':'zjsroom','id':'50b846d7a5988ac7bbc74b2a4f651c7f','type':'people','name':'zjsroom','url': ac7bbc74b2a4f651c7f','gender':-1,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':0,'badge':[]},{'is_followed':False, 'user_type':'people','is_following':'headline':'程序猿','url_token':'yi-di-jin-guang''id''e7d124798d91d28e983330ec2b72d311','type''people''name'?地?光 28e983330ec2b72d311','gender':-1,'is_advertiser':False,'avatar_url': 'is_org':False,'follower_count':0,'badge':{'is_followed':False,'avatar_url_tem 'user_type':'people','is_following':'headline':'歡迎號(hào):「」→城市|地 |規(guī)劃|經(jīng)濟(jì)','url_token':'joe1324','id':'130894ff204e72b96719a09b5a6565bc','type':'people','name':'','url': 2b96719a09b5a6565bc','gender':1,'is_advertiser':False,'avatar_url': 'is_o
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 高中物理第九章固體液體和物態(tài)變化第2節(jié)液體課件新人教版選修3-
- 高考數(shù)學(xué)全真模擬試題第12625期
- 【中考考點(diǎn)基礎(chǔ)練】第11章 內(nèi)能與熱機(jī) 2025年物理中考總復(fù)習(xí)(福建)(含答案)
- 2024年山東省泰安市中考地理試題含答案
- 2024至2030年中國(guó)無(wú)菌設(shè)備數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 2024至2030年中國(guó)數(shù)碼固體立體聲全自動(dòng)播放器數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 2024至2030年中國(guó)微電腦控制抽真空精密加酸機(jī)數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 2024至2030年中國(guó)引線式熱敏電阻器行業(yè)投資前景及策略咨詢(xún)研究報(bào)告
- 2010-2012年液態(tài)豆奶行業(yè)市場(chǎng)研究與競(jìng)爭(zhēng)力分析報(bào)告
- 2024至2030年中國(guó)土堿行業(yè)投資前景及策略咨詢(xún)研究報(bào)告
- 影視廣告策劃與制作課件
- 粉塵清掃記錄
- 大數(shù)據(jù)技術(shù)原理與應(yīng)用 完整版課件
- 接地裝置隱蔽工程驗(yàn)收記錄
- (完整)舌尖上的中國(guó)ppt
- 創(chuàng)新創(chuàng)業(yè)路演PPT
- 第5課 耕牛-戰(zhàn)馬 課件 八年級(jí)上冊(cè)
- 觀看公安民警違紀(jì)警示教育片心得體會(huì)三篇
- 再生水清水池施工技術(shù)措施
- 人教版四年級(jí)語(yǔ)文上冊(cè)精美課件第一單元習(xí)作推薦一個(gè)好地方
- 深基坑專(zhuān)項(xiàng)施工方案(專(zhuān)家論證)
評(píng)論
0/150
提交評(píng)論