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. ...
随机推荐
- [leetcode]134. Gas Station加油站
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. Y ...
- docker 容器创建参数错误记录
sudo docker ps -a -q sudo docker ps -a|cutawk '{print $1}' #删除前八条 sudo docker ps -a -q|head -n |xarg ...
- Qt Customize QVariant
Customize QVariant #include <QCoreApplication> #include <QVariant> #include <QDebug&g ...
- Castle ActiveRecord学习(七)使用日志
暂无 参考:http://terrylee.cnblogs.com/archive/2006/04/14/374829.html
- WHY JAVASCRIPT NEEDS TYPES
Types have a bad reputation for making code harder to read, adding unnecessary ceremony, and in gene ...
- 密码分析:使用 Ettercap 和 它的 ARP 毒化功能来嗅探流量
vim /etc/etterconf 将 ec_uid 和 ec_gid 改为 0 需要取消下面的 IPTABLES 行的注释.它在靠近文件末尾的 LINUX 一节 ettercap -G Shift ...
- 【JAVA 学习笔记1】代码注释
在JAVA中支持单行注释和多行注释 1.单行注释,只要在注释的一行代码中加上双斜杠即可 例如: // int a=2,b=4,c=8; 2.多行注释,在开始位置加上/* 结束位置加上*/ 例如 /* ...
- kubernetes 滚动更新发布及回滚
基本命令 记录历史 --record kubectl apply -f **** --record 查看当前状态 kubectl rollout status deployment/demo -w ...
- maven多模块启动required a bean of type com.xxx.xxx.service that could not be found.
Description: Field testService in com.xxx.xxx.api.controller.TestController required a bean of type ...
- .Net Core IFormFile 始终为空的问题
之前获取上传文件都是使用Request.Form.Files获取,直到这次改成定义形参 IFormFile时才遇到这个问题. // POST api/values [HttpPost] public ...