python vbs库_Python语言之requests库
發(fā)送請求、傳遞URL參數(shù)、定制headers、接受數(shù)據(jù),處理數(shù)據(jù)等
在Java中用httpclient jar包,在Python中用requests庫,即使沒有事先下載,在Pycharm開發(fā)工具中,出現(xiàn)提示時(shí)刻,同意安裝即可
1) 發(fā)送請求
url='http://baidu.com'
requests.post(url)
requests.put(url)
requests.delete(url)
requests.head(url)
requests.options(url)
GET: 請求指定的頁面信息,并返回實(shí)體主體。
HEAD: 只請求頁面的首部。
POST: 請求服務(wù)器接受所指定的文檔作為對所標(biāo)識(shí)的URI的新的從屬實(shí)體。
PUT: 從客戶端向服務(wù)器傳送的數(shù)據(jù)取代指定的文檔的內(nèi)容。
DELETE: 請求服務(wù)器刪除指定的頁面。
get 和 post比較常見 GET請求將提交的數(shù)據(jù)放置在HTTP請求協(xié)議頭中
POST提交的數(shù)據(jù)則放在實(shí)體數(shù)據(jù)中
2) 定制參數(shù)
import requests
response = requests.get("http://localhost:8083/showuser?name=germey&age=22")
response = requests.get("http://localhost:8083/showuser?name=germey&age=22")
response = requests.get("http://localhost:8083/showuser?name=germey&age=22")
data={
'name': 'germey',
'age': 22
}
response = requests.get("http://localhost:8083/showuser,param=data}
data2= (
('endDate', '2019-12-12'),
('pageIndex', 0),
('pageSize', 50),
('startDate', '2010-01-01')
)
data3= {
"endDate": "2019-12-12",
"pageIndex": 0,
"pageSize": 50,
"startDate": "2010-01-01"
}
response2=requests.post(url=url2,headers=headers2,data=json.dumps(data2))
response2=requests.post(url=url2,headers=headers2,data=json.dumps(data3))
print(response2.json())
3)定制header
url2='http://localhost:8094/common-api/v1/point/detail?social=AcxiomChina&user=VP巴黎戀人'
headers2={'token':'MTU1Mjg4NTQxOEFDWElPTS1XRUNIQVQ=','Content-Type':'application/json;charset=UTF-8'}
4)response的處理
response.json() 如果是json格式的返回,轉(zhuǎn)化為json格式
response.cookies
response.status_code
response.url
response.text
response.content
總結(jié)
以上是生活随笔為你收集整理的python vbs库_Python语言之requests库的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html文字竖直书写,css 文字竖直居
- 下一篇: java中br.readline_jav