Skip to content

Instantly share code, notes, and snippets.

@taizilongxu
Created August 27, 2016 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taizilongxu/623d4b45c96c773dfd1a3aac5c696fb3 to your computer and use it in GitHub Desktop.
Save taizilongxu/623d4b45c96c773dfd1a3aac5c696fb3 to your computer and use it in GitHub Desktop.
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