Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
requests
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
You can’t perform that action at this time.