import requests
from lxml import html
r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
print r.status_code
print r.headers
print r.encoding
print r.text
print r.json()
payload = {"wd": "a"}
r = requests.get("http://httpbin.org/get", params=payload)
print r.url
r = requests.get('https://github.com/timeline.json')
print r.json()
from PIL import Image
from io import BytesIO
i = Image.open(BytesIO(r.content))
url = 'http://example.com/some/cookie/setting/url'
r = requests.get(url)
print r.cookies['example_cookie_name']
cookies = dict(cookies_are='working')
r = requests.get(url, cookies=cookies, timeout=0.001)
'''
会话对象让你能够跨请求保持某些参数。它也会在同一个 Session 实例发出的所有请求之间保持 cookie,
期间使用 urllib3 的 connection pooling 功能。所以如果你向同一主机发送多个请求,底层的 TCP 连
接将会被重用,从而带来显著的性能提升
'''''
s = requests.Session()
s.get('http://httpbin.org/cookies/set/sessioncookie/123456789')
r = s.get("http://httpbin.org/cookies")
print r.text
'''
代理'''
import requests
proxies = {
"http": "http://10.10.1.10:3128",
"https": "http://10.10.1.10:1080",
}
requests.get("http://example.org", proxies=proxies)