python Requests 初级
来源:互联网 发布:双色球杀红球算法 编辑:程序博客网 时间:2024/06/06 09:11
import requests
r=requests.get('https://github.com/timeline.json')
r=requests.post("http://httpbin.org/post")
r=requests.put("http://httpbin.org/put")
r=requests.delete("http://httpbin.org/delete")
r=requests.head("http://httpbin.org/get")
r=requests.options("http://httpbin.org/get")
payload = {'key1': 'value1', 'key2': 'value2'}
r=requests.get("http://httpbin.org/get", params=payload)
print(r.url)
http://httpbin.org/get?key2=value2&key1=value1
from PIL import Image
from io import BytesIO
i=Image.open(BytesIO(r.content))
import requests
r=requests.get('https://github.com/timeline.json')
url='https://api.github.com/some/endpoint'
headers={'user-agent': 'my-app/0.0.1'}
r=requests.get(url, headers=headers)
payload=(('key1', 'value1'), ('key1', 'value2'))
r=requests.post('http://httpbin.org/post', data=payload)
print(r.text)
(json直接传递)
import json
url='https://api.github.com/some/endpoint'
payload={'some': 'data'}
r=requests.post(url, data=json.dumps(payload))
url='http://example.com/some/cookie/setting/url'
r=requests.get(url)
r.cookies['example_cookie_name']
'example_cookie_value'
发送你的cookies到服务器:
(Cookie 的返回对象为 RequestsCookieJar)
r='http://httpbin.org/cookies'
cookies=dict(cookies_are='working')
r=requests.get(url, cookies=cookies)
r.text
'{"cookies": {"cookies_are": "working"}}'
r = requests.get('http://github.com')
r.url
'https://github.com/'
r.status_code
200
r.history
[<Response [301]>]
r=requests.get('http://github.com', allow_redirects=False)
r.status_code
301
r.history
[]
阅读全文
0 0
- python Requests 初级
- python requests
- python requests
- Python Requests
- python Requests
- python Requests
- python requests
- Requests-Python
- python requests 高级用法
- Python Requests快速入门
- python-requests包
- Python Requests快速入门
- Python模块学习 - Requests
- python中的requests使用
- Python - cookielib [urllib2/requests]
- Python Requests简单运用
- python requests插件
- Python Requests快速入门
- Android 一起来看看 7.0 的新特性 FileProvider
- PAT (Advanced) 1001. A+B Format (20)
- 灌水的一天
- windows核心编程之亲缘性
- 编译原理与编译构造 文法的优化1
- python Requests 初级
- Android6.0+运行时权限的处理
- 所谓的跨域(Cross-Origin),究竟是什么?——你所不知道浏览器跨域的小知识
- TCP,UDP,HTPP关系
- android Thread和Runable区别 精讲
- 轻院1077字符串加密
- MySQL中的慢查询日志(Slow Query Log)
- 重写对象equals和compareTo方法
- antd-admin 错误排查