http://docs.python-requests.org/zh_CN/latest/user/quickstart.html
r = requests.get('http://httpbin.org/get', params=payload)
r.text --返回网页正文 HTML
r.encoding = 'ISO-8859-1' (可以改变解码规则)
爬取图片并保存在本地
import requests
from PIL import Image
from io import BytesIO
r = requests.get('https://avatar.csdn.net/A/B/A/3_hahahahalll.jpg')
imgbY=BytesIO(r.content)
i = Image.open(imgbY)
i.save("go.png","png")
JSON 响应内容
import requests
r = requests.get('https://api.github.com/events')
r.json()
headers = {
"User-Agent": "Mozilla/5.e (Macintosh; Intel Mac OSX10_9_ 5)AppleWebKit 537.36 (KHTML, like Gecko) Chrome",
"Accept": "text/html ,application/ xhtml+xml , application/ xml ;q=0.9, image/webp, */*;q=0.8"
}
r = requests.get(url, headers=headers)
url = 'http://example.com/some/cookie/setting/url'
r = requests.get(url)
r.cookies['example_cookie_name']
## 'example_cookie_value'
请求携带cookie
url = 'http://httpbin.org/cookies'
cookies = dict(cookies_are='working')
r = requests.get(url, cookies=cookies)