Python-随请求发送data/headers
来源:互联网 发布:排序算法比较次数 编辑:程序博客网 时间:2024/05/23 11:56
version:2.7.12
#coding=utf-8import urllibimport urllib2#url = 'http://www.baidu.com'url = 'https://hao.360.cn/?wd_xp1'values = {'name' : 'WHY', 'location' : 'SDU', 'language' : 'Python' }send_headers = {#'Host':'http://www.baidu.com', #'Host':'https://hao.360.cn/?wd_xp1', 'User-Agent':'Mozilla/5.0 (Windows NT 6.2; rv:16.0) Gecko/20100101 Firefox/16.0', 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Connection':'keep-alive'}data = urllib.urlencode(values,'utf8') # 编码工作dataHeaders = urllib.urlencode(send_headers,'utf8')#req = urllib2.Request(url)#req = urllib2.Request(url = url,headers = send_headers) # 发送请求同时传【headers】【post】#req = urllib2.Request(url+'?'+dataHeaders) # 发送请求同时传【headers】【get】#req = urllib2.Request(url+'?'+data) # 发送请求同时传【data】【get方式】#req = urllib2.Request(url,data) # 发送请求同时传【data】【post方式】【百度不可用,360可用】req = urllib2.Request(url,data,send_headers) # 发送请求同时传【data+headers】【post方式】response = urllib2.urlopen(req) #接受反馈的信息print response.info()#打印头部信息print "\"real path\" :",response.geturl()the_page = response.read() #读取反馈的内容print the_page.decode('UTF8')
0 0
- Python-随请求发送data/headers
- 使用python的requests 发送multipart/form-data 请求
- 使用python的requests 发送multipart/form-data 请求
- python学习:headers和data的获取
- http请求(Python爬虫headers)
- python爬虫设置请求消息头(headers)
- python发送HTTP请求
- python发送HTTP请求
- python发送HTTP请求
- python发送post请求
- python发送post请求
- python发送http请求
- python 发送http请求
- python发送HTTP请求
- python发送get请求
- python 发送post请求
- python发送HTTP GET请求
- 用python发送put请求
- Mac使用笔记(一):文件显示完整路径
- 备忘链接
- 设置paint.setXfermode(mMode)无效
- LeetCode 319. Bulb Switcher
- 十二之再续:快速排序算法之所有版本的c/c++实现
- Python-随请求发送data/headers
- 洛谷 P1019 [NOIP2000 T3] 单词接龙
- opencv学习(二)之图像的加载、显示、保存
- ECMAScript6笔记:let和const命令
- LoRa点对点系统3 与PC接口
- Android Studio 导入.so文件
- 解决SpringMVC表单重复提交总结
- 新的开始
- 彻底关闭win10后台同步数据