The methods of Requests
requests.* | details |
---|---|
requests.request() | Construct a request to support the following basel methods |
requests.get(url,params=None,**kwargs) | url: links; params: url中的额外参数,字典或者字节流格式,可选; **kwargs: 12个控制访问的参数,可选; |
requests.head() | get the head info of HTML, to HTTP’s HEAD |
requests.post() | submit post to HTML, to HTTP’s POST |
requests.put() | submit PUT to HTML, to HTTP’s PUT |
requests.patch() | submit the modification request, to HTTP’s PATCH |
requests.delete() | submit the delete to HTML, to HTML’s DELETE |
The objects of Requests
Response:
Request:
The properties of Response | Details |
---|---|
r.status_code | the status of HTTP’s response, 200 is right, 404 wrong; |
r.text | the alphabetic sting of HTTP’s response content, is the content of url; |
r.encoding | the coding scheme from the guest of HTTP header |
r.apparent_encoding | the coding scheme from the analisis of content of url |
r.content | the binary scheme of HTTP’s response |
The general code framework of reptile
1 | import requests |
The excepting handing of Requests
excepting | details |
---|---|
request.ConnectionError | internet connection error, e.g.: DNS find error, reject connection |
requests.HTTPError | HTTP false error |
requests.URLRequired | deficiency error of URL |
requests.TooManyRedirects | error: over the redirect time |
requests.ConnectTimeout | timeout when connect the service |
requests.Timeout | timeout when get url |
A method of error to Requests
r.raise_for_status() : if response not 200; return requests.HTTPError
e.g.: last step
Http Protocol:
HTTP,Hypertext Transfer Protocol, 超文本传输协议
The format of URL:
URL: http://host[:port][path]
host: the legal internet host name or ip address
port: the port number, default: 80
path: the source path of response