Python发送get、post请求
import json
import requests
#获取北京天气
#
#url= "https://wis.qq.com/weather/common?source=xw&weather_type=forecast_1h|forecast_24h|index|alarm|limit|tips&province=北京&city=北京&county=昌平区"
#req = requests.get(url)# 发送请求
#print(req.text)# 得到的是json格式
#print(req.json)# 得到的是字典格式
#print(type(req.text))
#print(type(req.json)) #发送post请求,登录并将个人信息保存到本地
url = "https://api.apiopen.top/developerLogin"
data = {'name':'xxx','passwd':'xxx'}
req = requests.post(url,data)#发送post请求,第一个参数是URL,第二个参数是请求数据
filename = 'D:/write_data.txt'
with open(filename,'w') as f:
f.write(str(req.json())+"\n")
print(req.json()) #入参是json
# url = 'http://api.nnzhp.cn/api/user/add_stu'
# data = {'name':'mapeipei','grade':'Mp123456','phone':15601301234}
# req = requests.post(url,json=data)
# print(req.json()) #添加header
# url = 'http://api.nnzhp.cn/api/user/all_stu'
# header = {'Referer':'http://api.nnzhp.cn/'}
# res = requests.get(url,headers=header)
# print(res.json()) # 添加cookie
# url = 'http://api.nnzhp.cn/api/user/gold_add'
# data = {'stu_id':231,'gold':123}
# cookie = {'niuhanyang':'7e4c46e5790ca7d5165eb32d0a895ab1'}
# req = requests.post(url,data,cookies=cookie)
# print(req.json()) #上传文件
# url = 'http://api.nnzhp.cn/api/file/file_upload'
# f = open(r'E:\besttest\te\python-mpp\day7\练习\11.jpg','rb')
# r = requests.post(url,files={'file':f})
# users_dic = r.json()
# print(users_dic) # 下载文件
# url = 'http://www.besttest.cn/data/upload/201710/f_36b1c59ecf3b8ff5b0acaf2ea42bafe0.jpg'
# r = requests.get(url)
# print(r.status_code)#获取请求的状态码
# print(r.content)#获取返回结果的二进制格式
# fw = open('mpp.jpg','wb')
# fw.write(r.content)
# fw.close() #把浏览器页面下载到本地 保存网页,可以理解为简单的爬虫工具
#url='http://www.nnzhp.cn/archives/630'
#r = requests.get(url)
#f = open('nnzhp.html','wb')
#f.write(r.content)
#f.close()
Python发送get、post请求的更多相关文章
- python发送HTTP POST请求
1. 127.0.0.1和0.0.0.0 127.0.0.1是一个回送地址,指本地机,一般用来本机测试使用,使用127.0.0.1启的服务只能在本地机器上访问,使用0.0.0.0启的服务可以在其他机器 ...
- python 发送 get post请求
GET请求: python2.7: import urllib,urllib2 url='http://192.168.199.1:8000/mainsugar/loginGET/' textmod ...
- 解决python发送multipart/form-data请求上传文件的问题
服务器接收文件时,有时会使用表单接收的方式,这意味着我们需要使用Python的requests上传表单数据和文件. 常用的方式一般如下: data = { 'name': 'nginx' } file ...
- requests模块--python发送http请求
requests模块 在Python内置模块(urllib.urllib2.httplib)的基础上进行了高度的封装,从而使得Pythoner更好的进行http请求,使用Requests可以轻而易举的 ...
- python发送post和get请求
python发送post和get请求 get请求: 使用get方式时,请求数据直接放在url中. 方法一. import urllib import urllib2 url = "http: ...
- python 发送post和get请求
摘自:http://blog.163.com/xychenbaihu@yeah/blog/static/132229655201231085444250/ 测试用CGI,名字为test.py,放在ap ...
- Python接口测试实战2 - 使用Python发送请求
如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...
- python发送GET或POST请求以便干一些趣事
适合级别:入门,中级 关键字 :python, http, GET, POST, 安全, 模拟, 浏览器, 验证码,图片识别, google 1 此文不是关于黑客或安全话题的! 2 使用脚本程序发 ...
- Python发送http请求时遇到问题总结
1.报错信息为“ERROR 'str' object has no attribute 'endwith'”,排查发现endswith方法名写错了,少了s,写成了 'endwith' if inter ...
- python使用requests发送multipart/form-data请求数据
def client_post_mutipart_formdata_requests(request_url,requestdict): #功能说明:发送以多部分表单数据格式(它要求post的消息体分 ...
随机推荐
- fiddler本地调试
参考:https://blog.csdn.net/letasian/article/details/75021656 有关fiddler基础用法的介绍详见我的上一篇博客:http://www.cnbl ...
- OpenCV计算机视觉编程攻略(第三版)源码
去年买了这本OpenCV的书,感觉还不错,但是书上没有给出下载源码的地方,在网上找了下,还好找到了,现在分享给大家: 链接: https://pan.baidu.com/s/1IqAay1IZ8g-h ...
- 如何设置远程MongoDB!
默认情况下V服务连接着本地mongoDB服务,如果想连接到其他mongoDB服务,请按如下设置: 方法一:通过控制台修改 进入控制台 http://x.x.x.x:xxxx/system/consol ...
- MySQL数据库高可用方案
一.什么是高可用性: 高可用性=可靠性,它的本质就是通过技术和工具提高可靠性,尽可能长时间保持数据可用和系统运行,实现高可用性的原则,首先要消除单点故障,其次通过冗余机制实现快速恢复,还有就是实现容错 ...
- 在Linux下安装nginx服务器详细教程
首先安装centos的扩展源 yum install epel-release 安装Nginx 方法一: yum install nginx -y 查看版本号,开启nginx,查看进程 nginx – ...
- Java实现获取一个随机的两位数
import java.util.Random; //获取一个随机的 两位数public class getrandomdouble { public static void main(String[ ...
- go微服务系列(一) go micro入门
1. 什么是go micro 1.1 go micro作用 1.2 go micro架构组成 2. go micro入门 3. 结合consul进行服务注册/发现 3.1 consul的安装 3.2 ...
- JS与React分别实现倒计时(天时分秒)
JS方法 html部分 <div class="clock"> <i></i> 天 <i></i> : <i> ...
- Vue 使用$createElement自定义文本
有时候弹窗或者一些特殊的区域需要自定义一些html元素来显示(snabbdom) const h = this.$createElement this.$msgbox({ title: '提示', m ...
- The Definitive Guide to Ruby's C API The Ruby C API Running Ruby in C Running C in Ruby
最近在研究如何在C/C++中 嵌入ruby脚本,很感谢找到了一篇文章,分享一下. The Definitive Guide to Ruby's C API