Last active
January 4, 2019 02:34
-
-
Save ayuLiao/dfb47f6b23f5eda92ae38fc5fc9ae23b 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
''' | |
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