Created
August 27, 2016 10:10
-
-
Save taizilongxu/623d4b45c96c773dfd1a3aac5c696fb3 to your computer and use it in GitHub Desktop.
requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.requests('http://www.example.com') | |
r.request.headers # 请求头 | |
r.status_code | |
r.url # 访问网址 | |
r.headers # 返回头部信息 | |
r.encoding | |
r.text #内容部分(PS,由于编码问题,建议这里使用r.content) | |
r.json() | |
# URL传参 | |
payload = {'wd': 'test', 'rn': '100'} | |
r = requests.get("http://www.example.com", params=payload) | |
# 自定义头部请求 | |
headers = {'User-Agent': 'alexkh'} | |
r = requests.get('http://www.example.com', headers = headers) | |
# POST | |
payload = {'key1': 'value1', 'key2': 'value2'} | |
r = requests.post("http://httpbin.org/post", data=payload) | |
# HTTP auth | |
requests.get('https://api.github.com/user', auth=('user', 'pass')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment