Python程序中添加代理信息代码示例
2019-03-19 17:35
288 查看
requests
#! -*- encoding:utf-8 -*- import requests import random # 要访问的目标页面 targetUrl = "http://httpbin.org/ip" # 要访问的目标HTTPS页面 # targetUrl = "https://httpbin.org/ip" # 代理服务器 proxyHost = "t.16yun.cn" proxyPort = "31111" # 代理隧道验证信息 proxyUser = "username" proxyPass = "password" proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % { "host" : proxyHost, "port" : proxyPort, "user" : proxyUser, "pass" : proxyPass, } # 设置 http和https访问都是用HTTP代理 proxies = { "http" : proxyMeta, "https" : proxyMeta, } # 设置IP切换头 tunnel = random.randint(1,10000) headers = {"Proxy-Tunnel": str(tunnel)} resp = requests.get(targetUrl, proxies=proxies, headers=headers) print resp.status_code print resp.text
相关文章推荐
- PHP爬虫程序中添加代理信息代码示例
- Python实现自动添加脚本头信息的示例代码
- Python实现自动添加脚本头信息的示例代码
- 在python获取网页的代码中添加头信息模拟浏览器
- 使用Python的Twisted框架编写非阻塞程序的代码示例
- Python中捕捉详细异常信息的代码示例
- 给Asus WL500G Deluxe无线路由器日志文件添加IP地址地理位置信息的Python小程序
- Python抓取手机号归属地信息示例代码
- Nuva 示例代码(每日一帖)之 添加版权信息
- Python抓取手机号归属地信息示例代码
- Android获取apk程序签名信息代码示例
- Python爬取附近餐馆信息代码示例
- Python---购物车更新程序 商品信息存在文件当中,用户购买记录要打印已购商品,余额。卖家可以添加商品,修改价格。
- [ --> C Language<-- ] employee信息添加,删除,列表的示例程序
- 黄聪:python+MySQLdb操作Mysql数据库示例代码程序教程
- Spring程序读取Cloud Foundry服务信息示例代码
- Python实现socket信息发送和监听的简单代码示例
- Python实现比较扑克牌大小程序代码示例
- python登录并爬取淘宝信息代码示例
- 自动添加VS 2008 代码文件版权信息 注释,用小程序实现更改