Requests is an HTTP client library for Python , similar to urllib,urllib2 , but urllib2 API is more complex, such as implementing a post or get function requires a lot of code.
Let me briefly introduce this library today, and after I have read the official documentation, write a full-fledged one.
#-*-Coding:utf8-*-import requestr = requests.get (' http://www.zhidaow.com ') #发送请求r. status_code# Return status Code r.headers[' Content-type '] #返回头部信息r. encoding# return encoded information r.text# return Content Part # various HTTP requests r = Requests.post (' http://httpbin.org/post ') 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 ') #带有参数的请求例子payload = {' wd ': ' Zhang Yanan ', ' rn ': ' + '}r = Requests.get (' http://www.baidu.com/s ', Parama = payload) Print r.url# get json result r = Requests.get (' ... ') r.join () [' Data '] [ ' Country ']
Python's Concise Path-----requests Library