python3.6的request
request实例1:
import requests
payload = {'key1':'value','key2':'value2'}
url = "http://httpbin.org/get"
headers = {'content-type': 'application/json'}
res = requests.get(url,params=payload,headers=headers)
res.encoding="utf-8"
print("1.url: ")
print(res.url)
print("2.text: ")
print(res.text)
print("3.json: ")
print(res.json())
print("4.status_code: ")
print(res.status_code)
结果:
1.url:
http://httpbin.org/get?key1=value&key2=value2
2.text:
{
"args": {
"key1": "value",
"key2": "value2"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.18.4"
},
"origin": "117.25.182.2",
"url": "http://httpbin.org/get?key1=value&key2=value2"
} 3.json:
{'args': {'key1': 'value', 'key2': 'value2'}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Content-Type': 'application/json', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.18.4'}, 'origin': '117.25.182.2', 'url': 'http://httpbin.org/get?key1=value&key2=value2'}
4.status_code:
200
request实例2:
import requests
payload = {'key1':'value1','key2':'value2'}
url = "http://httpbin.org/post"
headers = {'content-type': 'application/json'}
res =requests.post(url,data=payload,headers=headers)
print("1.url: ")
print(res.url)
print("2.text: ")
print(res.text)
print("3.json: ")
print(res.json())
print("4.status_code: ")
print(res.status_code)
结果:
1.url:
http://httpbin.org/post
2.text:
{
"args": {},
"data": "key1=value1&key2=value2",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Content-Length": "23",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.18.4"
},
"json": null,
"origin": "117.25.182.2",
"url": "http://httpbin.org/post"
} 3.json:
{'args': {}, 'data': 'key1=value1&key2=value2', 'files': {}, 'form': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Content-Length': '23', 'Content-Type': 'application/json', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.18.4'}, 'json': None, 'origin': '117.25.182.2', 'url': 'http://httpbin.org/post'}
4.status_code:
200
request实例3:
import requests
url = 'http://httpbin.org/cookies'
cookies = dict(cookies_are='working')
r = requests.get(url, cookies=cookies)
print("1.url: ")
print(res.url)
print("2.text: ")
print(res.text)
print("3.json: ")
print(res.json())
print("4.status_code: ")
print(res.status_code)
结果:
1.url:
http://httpbin.org/post
2.text:
{
"args": {},
"data": "key1=value1&key2=value2",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Content-Length": "23",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.18.4"
},
"json": null,
"origin": "117.25.182.2",
"url": "http://httpbin.org/post"
} 3.json:
{'args': {}, 'data': 'key1=value1&key2=value2', 'files': {}, 'form': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Content-Length': '23', 'Content-Type': 'application/json', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.18.4'}, 'json': None, 'origin': '117.25.182.2', 'url': 'http://httpbin.org/post'}
4.status_code:
200
python3.6的request的更多相关文章
- python3.6 urllib.request库实现简单的网络爬虫、下载图片
#更新日志:#0418 爬取页面商品URL#0421 更新 添加爬取下载页面图片功能#0423 更新 添加发送邮件功能# 优化 爬虫异常处理.错误页面及空页面处理# 优化 爬虫关键字黑名单.白名单,提 ...
- python3 spider [ urllib.request ]
# # 导入urllib库的urlopen函数 # from urllib.request import urlopen # # 发出请求,获取html # html = urlopen(" ...
- python3中urllib库的request模块详解
刚刚接触爬虫,基础的东西得时时回顾才行,这么全面的帖子无论如何也得厚着脸皮转过来啊! 原帖地址:https://www.2cto.com/kf/201801/714859.html 什么是 Urlli ...
- Python3使用request/urllib库重定向问题
禁止自动重定向 python3的urllib.request模块发http请求的时候,如果服务器响应30x会自动跟随重定向,返回的结果是重定向后的最终结果而不是30x的响应结果. request是靠H ...
- python3下urlopen解析中文url编码错误
这是在ipython下测试的结果: In [24]: x Out[24]: 'http://127.0.0.1:8000/xxx/?id=a45ex0bad3c9&game=五子棋' In [ ...
- python3 抓取网页资源的 N 种方法
1. 最简单 import urllib.request response = urllib.request.urlopen('http://python.org/') html = response ...
- Python3中urllib详细使用方法(header,代理,超时,认证,异常处理)
urllib是python的一个获取url(Uniform Resource Locators,统一资源定址器)了,我们可以利用它来抓取远程的数据进行保存哦,下面整理了一些关于urllib使用中的一些 ...
- Python3中urllib详细使用方法(header,代理,超时,认证,异常处理) 转
urllib是python的一个获取url(Uniform Resource Locators,统一资源定址器)了,我们可以利用它来抓取远程的数据进行保存哦,下面整理了一些关于urllib使用中的一些 ...
- urllib库详解 --Python3
相关:urllib是python内置的http请求库,本文介绍urllib三个模块:请求模块urllib.request.异常处理模块urllib.error.url解析模块urllib.parse. ...
随机推荐
- webkit com wrapper 推荐!
https://groups.google.com/forum/#!topic/microsoft.public.vb.general.discussion/ZaFY95aDZoY http://ww ...
- [Java]通过java获取计算机名
通过java获取计算机名 String hostname = "Unknown"; try { InetAddress addr; addr = InetAddress.getLo ...
- 关于自动ui的多个处理我的解决方案, 不知道大家怎么处理
( pathpp ="D:\\pyc-tools\\ms\\newdate\\maxinfo" DialogMonitorOPS.unRegisterNotification id ...
- JavaScript 语法总结2
1. 对象的toString()和valueOf(). - toString() 和Java中的toString() 一样 - valueOf(), 和toString() 都是用来进行类型转换的方法 ...
- 马婕 2014MBA专硕考试 报刊选读 3 禽流感考验政府的透明度(转)
http://blog.sina.com.cn/s/blog_3e66af4601015z0n.html Bird flu cases test government transparency 禽流感 ...
- UVa 10537 The Toll! Revisited (最短路)
题意:给定一个图,你要从 s 到达 t,当经过大写字母时,要交 ceil(x /20)的税,如果经过小写字母,那么交 1的税,问你到达 t 后还剩下 c 的,那么最少要带多少,并输出一个解,如果多个解 ...
- html 中的<script>标签
https://www.w3.org/TR/html51/semantics-scripting.html#the-script-element 一. <script type='text/ja ...
- Appium常用API(二)
接前面的常用API(一),本文接着介绍如下: 1.press_keycode press_keycode(self, keycode, metastate=None): Sends a keycode ...
- 23 DesignPatterns学习笔记:C++语言实现 --- 2.7 Proxy
23 DesignPatterns学习笔记:C++语言实现 --- 2.7 Proxy 2016-07-18 (www.cnblogs.com/icmzn) 模式理解
- 終于解決调用wordpress 4.3 xmlrpc api 发布包含分类的文章时返回“抱歉,文章类型不支持您的分类法”错误的問題
這個問題我找了很多資料都沒有明說是如何解決,后來突發奇想得出我的解決方案如下,所以特此記錄一下: object postId = blogService.NewPost(0,"admin&q ...