python基本库系列一:Request
生活随笔
收集整理的這篇文章主要介紹了
python基本库系列一:Request
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Requests請(qǐng)求
參考 python requests用法總結(jié)
基本get請(qǐng)求方式
import requestsurl = 'http://www.baidu.com' # 參數(shù) params = {'name':'vito', 'passwd': 'otiv765'} params = {'name':'vito', 'sex': ['s', 'm']} # 參數(shù)列表形式 &sex=s&sex=mr = requests.get(url, params) r.encoding = "utf-8" #中午解碼 # r.text r.content r.json r.status_code r.raw# 保存請(qǐng)求返回內(nèi)容 with open('python/request.html', 'wb') as f:for chunk in r.iter_content():f.write(chunk) 復(fù)制代碼post請(qǐng)求方式
r = requests.post(url, data={'name':'vito'}) 復(fù)制代碼添加headers & cookies
headers= {'user-agent': 'my-app/0.0.1'} r = requests.get(url, headers=headers, cookies=dict(cookies_are='working')) 復(fù)制代碼請(qǐng)求用戶代理
proxies = {'http': 'http://10.10.1.10:3128','https': 'http://10.10.1.10:1080', }requests.get('http://example.org', proxies=proxies) 復(fù)制代碼轉(zhuǎn)載于:https://juejin.im/post/5b74d94f6fb9a009cb694696
總結(jié)
以上是生活随笔為你收集整理的python基本库系列一:Request的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HAProxy http和https都使
- 下一篇: Python学习笔记 (1)Hello