ITPub博客

首页 > 大数据 > 可视化 > 爬虫代码

爬虫代码

原创 可视化 作者:laical 时间:2021-06-10 17:15:06 0 删除 编辑
    #! -*- 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


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69946368/viewspace-2776387/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 抓取微信小程序
请登录后发表评论 登录
全部评论

注册时间:2019-09-05

  • 博文量
    9
  • 访问量
    4249