Python3.6通过自带的urllib通过get或post方法请求url的实例
2019/7/15 0:47:43
本文主要是介绍Python3.6通过自带的urllib通过get或post方法请求url的实例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
废话不多说,直接上代码:
# coding:utf-8 from urllib import request from urllib import parse url = "http://10.1.2.151/ctower-mall-c/sys/login/login.do" data = {"id":"wdb","pwd":"wdb"} params="?" for key in data: params = params + key + "=" + data[key] + "&" print("Get方法参数:"+params) headers = { #heard部分直接通过chrome部分request header部分 'Accept':'application/json, text/plain, */*', 'Accept-Encoding':'gzip, deflate', 'Accept-Language':'zh-CN,zh;q=0.8', 'Connection':'keep-alive', 'Content-Length':'14', #get方式提交的数据长度,如果是post方式,转成get方式:【id=wdb&pwd=wdb】 'Content-Type':'application/x-www-form-urlencoded', 'Referer':'http://10.1.2.151/', 'User-Agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36' } data = parse.urlencode(data).encode('utf-8') req = request.Request(url, headers=headers, data=data) #POST方法 #req = request.Request(url+params) # GET方法 page = request.urlopen(req).read() page = page.decode('utf-8') print(page)
以上这篇Python3.6通过自带的urllib通过get或post方法请求url的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持找一找教程网。
这篇关于Python3.6通过自带的urllib通过get或post方法请求url的实例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python