requests-get请求
基本用法
#! /usr/bin/python3
# -*- congfig:utf-8 -*-
import requests
def test_get(url):
r = requests.get(url)
print(r.text)
if __name__ == "__main__":
url = "http://httpbin.org/get"
test_get(url)
{
"args": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.23.0",
"X-Amzn-Trace-Id": "Root=1-5f282e79-518da48d5ed76a546e05f8bf"
},
"origin": "111.18.36.169",
"url": "http://httpbin.org/get"
}
url参数
#! /usr/bin/python3
# -*- congfig:utf-8 -*-
import requests
def test_get(url):
params = {'user':"admin","password":"123456"}
r = requests.get(url)
print(r.text)
if __name__ == "__main__":
url = "http://httpbin.org/get"
test_get(url)
{
"args": {
"password": "123456",
"user": "admin"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.23.0",
"X-Amzn-Trace-Id": "Root=1-5f282f40-e0a0e61c7ecb451f6e9a51db"
},
"origin": "111.18.36.169",
"url": "http://httpbin.org/get?password=123456&user=admin"
}