Reprinted learning: https://www.cnblogs.com/alex3714/articles/8359404.html
A, Requests library introduction
Requests are using python language based urllib written, using the HTTP protocol Apache2 Licensed open source library.
Two, Requests basic library use
import requests response = requests.get("https://www.baidu.com") print(response.status_code) print(response.text) print(response.cookies) print(response.content)
Site in many cases there will be problems if the direct response.text garbled, often used solution is as follows:
import requests response = requests.get("https://www.baidu.com")
方法1: print(response.content.decode("utf-8")) # 方法2: response.encoding="utf-8" print(response.text)
Three, Requests request
import requests requests.post("http://httpbin.org/post") requests.put("http://httpbin.org/put") requests.delete("http://httpbin.org/delete") requests.head("http://httpbin.org/get") requests.options("http://httpbin.org/get")