作者: yiniuyun0
查看: 972|回复: 0
打印 上一主题 下一主题

Python添加代理代码示例

[复制链接]
跳转到指定楼层
楼主
yiniuyun0 发表于 2019-6-6 17:21:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
查看: 972|回复: 0

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
以上是python的代理添加示例,如果是其他的语言编写的可以去官网看下相应的接入指南 www.16yun.cn

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播
回复 论坛版权

使用道具 举报

您需要登录后才可以回帖 登录 | 加入CSkin博客

本版积分规则

QQ|申请友链|小黑屋|手机版|Archiver|CSkin ( 粤ICP备13070794号

Powered by Discuz! X3.2  © 2001-2013 Comsenz Inc.  Designed by ARTERY.cn
GMT+8, 2024-6-1 22:51, Processed in 0.517444 second(s), 32 queries , Gzip On.

快速回复 返回顶部 返回列表