A get request
import requests
url='http://www.baidu.com'
params={'wd':'zhihu'}
response=requests.get(url,params=params)
print(response.url)
response.encoding='utf-8'
print(response.text)
Copy the code
A post request
url = "http://www.sxt.cn/index/login/login.html"
formdata = {
"user": "17703181473"."password": "123456"
}
response = requests.post(url, data=formdata)
response.encoding = 'utf-8'
print(response.text)
Copy the code
Set the request header
import requests
from fake_useragent import UserAgent
headers={
'User-Agent':UserAgent().chrome
}
r=requests.get('http://www.zhidaow.com',headers=headers)
print(r.request.headers['User-Agent'])
Copy the code
Set the timeout
requests.get('http://github.com', timeout=0.001)
Copy the code
Set the agent
import requests
from fake_useragent import UserAgent
url='http://httpbin.org/get'
proxies={
'http':'http://113.194.139.160:9999'
}
r=requests.get(url,proxies=proxies)
print(r.text)
Copy the code