Import requests
You can use the Magic requests module below!
1. Sending data to a Web page
>>> payload = {'Key1':'value1','Key2': ['value2','Value3']}>>> r = Requests.get ('Http://httpbin.org/get', params=Payload)>>>Print(r.url) http:Httpbin.org/get?key1=value1&key2=value2&key2=value3
The post is similar to the get method, except that it is not params= ... But data= ...
>>> r = requests.put ("http://httpbin.org/put")>>> r = Requests.delete ("http://httpbin.org/delete")>>> r = Requests.head ( " Http://httpbin.org/get " )>>> r = requests.options ("http://httpbin.org/get")
2. Save the response to a file (official document recommended METHOD)
' WB ' as FD :for in r.iter_content (chunk_size): fd.write (chunk)
3. Some properties of R
R.encoding #编码
R.status_code #状态码 (404,200 Etc.)
R.raise_for_status () #如果状态码不是200会发起报错
4. Advanced Usage (session object-emulation Web page operation): http://cn.python-requests.org/zh_CN/latest/user/advanced.html#advanced
Python Requests Module Learning