Skip to content

Instantly share code, notes, and snippets.

@ayuLiao
Last active January 4, 2019 02:34
Show Gist options
  • Save ayuLiao/dfb47f6b23f5eda92ae38fc5fc9ae23b to your computer and use it in GitHub Desktop.
Save ayuLiao/dfb47f6b23f5eda92ae38fc5fc9ae23b to your computer and use it in GitHub Desktop.
requests 简单用法
'''
Get function
'''
payload = {'key1': 'value1', 'key2': 'value2'}
r = requests.get("http://httpbin.org/get", params=payload)
print(r.text)
# 如果返回信息是json
print(r.json())
'''
POST function
'''
r = requests.post('http://httpbin.org/post', data = {'key':'value'})
'''
header
'''
headers = {'user-agent': 'my-app/0.0.1'}
r = requests.get(url, headers=headers)
'''
cookie
'''
cookies = dict(cookies_are='working')
r = requests.get(url, cookies=cookies)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment