Python发送带header的http请求
2017-01-13 15:13
447 查看
简单的header
包含较多元素的header
import urllib2 request = urllib2.Request('http://example.com/') request.add_header('User-Agent', 'fake-client') response = urllib2.urlopen(request) print request.read()
包含较多元素的header
import urllib,urllib2 url = 'http://example.com/' headers = { 'Host':'example.com', 'Connection':'keep-alive', 'Cache-Control':'max-age=0', 'Accept': 'text/html, */*; q=0.01', 'X-Requested-With': 'XMLHttpRequest', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36', 'DNT':'1', 'Referer': 'http://example.com/', 'Accept-Encoding': 'gzip, deflate, sdch', 'Accept-Language': 'zh-CN,zh;q=0.8,ja;q=0.6' } data = None req = urllib2.Request(url, data, headers) response = urllib2.urlopen(req) html = response.read()
相关文章推荐
- 网络类型IPv4和IPv6什么意思?区别?
- OHSCE入门教程(四)-大肚函数PHP轻松搞HTTP(S)API(URL/REST)
- 使用ACL匹配奇偶网络号及IP地址
- 虚拟机VMware3种网络模式(桥接、nat、Host-only)的工作原理
- C# Socket TCP通信,连接服务器
- 使用 Scrapy 构建一个网络爬虫
- HTTP协议系列(2)--顺带离职的一些想法
- Android引用开源框架通过AsyncHttpClient实现文件上传
- SDN开发实战(2)-透明HTTP代理[Openflow+floodlight]
- Vmware CentOS虚拟机网络初始设置
- 如何用 TensorFlow 实现生成式对抗网络(GAN)
- Android 一个改善的okHttp封装库
- 计算机网络——物理层
- Http请求中Content-Type讲解以及在Spring MVC注解中produce和consumes配置详解
- 为微信小程序开发做准备,在Centos 6.8下利用letsencrypt.sh脚本为nginx 配置免费https证书
- http参数中特殊字符处理
- 深度学习(四十五)条件对抗网络
- MyEclipse配置https连接
- 开机注册联通2G网络
- 网络安全解决方案