【问题标题】:How to use nordvpn servers as proxy for python requests?如何使用 nordvpn 服务器作为 python 请求的代理?
【发布时间】:2021-02-07 11:16:04
【问题描述】:

我正在尝试使用 nordvpn 为 python 请求创建代理列表,但我似乎无法确定将服务器编写为代理的正确格式。

据我了解,格式是这样的,以这个服务器为例:

proxy = {
    'http': "username:password@us6181.nordvpn.com",
    'https': "username:password@us6181.nordvpn.com"
}

我尝试了各种组合:

  1. 我的登录邮箱和密码
  2. 我的 nordvpn 帐户用户名和密码
  3. 我意识到并非所有服务器都可以用作代理,所以我确定它们是
  4. 我尝试使用 udp/tcp 而不是 http/https

这些尝试都没有奏效,我真的希望有人能告诉我正确的方法。

【问题讨论】:

    标签: python proxy python-requests vpn openvpn


    【解决方案1】:

    这是我制作的一个简单脚本:

    import requests
    from requests.auth import HTTPProxyAuth
    import re
    import random
    #this is some proxy to use for nordvpn
    #196.240.57.107
    #37.120.217.219
    up1 = ['username:password'
    ]
    up2 = random.choice(up1)
    u1 = re.findall(r'[\w]+:', up2)
    p1 = re.findall(r':+[\w]+[\w]', up2)
    u2 = str(u1)
    u3 = u2.replace(':', '')
    u3 = u3.replace('[', '')
    u3 = u3.replace("'", '')
    u3 = u3.replace(']', '')
    p2 = str(p1)
    p3 = p2.replace(':', '')
    p3 = p3.replace('[', '')
    p3 = p3.replace("'", '')
    p3 = p3.replace(']', '')
    proxies = {"http":"http://217.138.202.147"}
    print(s)
    auth = HTTPProxyAuth(u3, p3)
    x = requests.get("http://ifconfig.me/ip")
    print('Real ip: ' + x.text)
    try:
        r = requests.get("http://ipv4.icanhazip.com", proxies=proxies, auth=auth)
        print(r.text)
    except requests.exceptions.ProxyError:
        proxies = {"https":"http://217.138.202.147"}
        r = requests.get("http://ipv4.icanhazip.com/", proxies=proxies, auth=auth)
        print(r.text)
    

    有些代理无法工作,您必须对其进行测试 和一个测试员

    import requests
    from requests.auth import HTTPProxyAuth
    import re
    import random
    list1 = []
    def main():
        c1 = random.randint(0,230)
        c2 = str(c1)
        c3 = c2.replace("'", '')
        url = 'https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters={"country_id":' + c3 + '}'
        headers = {
            'accept': "application/json/",
            'content-type': "application/json"
            }
        response = requests.request("GET", url, headers=headers)
        rep1 = response.text
        rep2 = re.findall(r'"ip":"[\d]+.[\d]+.[\d]+.[\d]+"', rep1)
        rep3 = str(rep2)
        if '[]' not in rep3:
            rep4 = rep3.replace('"ip":"', '')
            rep4 = rep4.replace("'", '')
            rep4 = rep4.replace('"', '')
            rep4 = rep4.replace(']', '')
            rep4 = rep4.replace('[', '')
            rep4 = rep4.replace(',', '')
            rep5 = rep4.split()
            for list2 in rep5:
                list1.append(list2)
        if '[]' in rep3:
            main()
    main()
    for a in list1:
        try:
            prox = a
            up1 = ['username:password'
            ]
            up2 = random.choice(up1)
            u1 = re.findall(r'[\w]+:', up2)
            p1 = re.findall(r':+[\w]+[\w]', up2)
            u2 = str(u1)
            u3 = u2.replace(':', '')
            u3 = u3.replace('[', '')
            u3 = u3.replace("'", '')
            u3 = u3.replace(']', '')
            p2 = str(p1)
            p3 = p2.replace(':', '')
            p3 = p3.replace('[', '')
            p3 = p3.replace("'", '')
            p3 = p3.replace(']', '')
            proxies = {"http":"http://" + prox}
            auth = HTTPProxyAuth(u3, p3)
            r = requests.get("http://ipv4.icanhazip.com", proxies=proxies, auth=auth)
            if '<p>The following error was encountered while trying to retrieve the URL: <a' in r:
                print(prox + ' Auth failed')
            elif '<p>The following error was encountered while trying to retrieve the URL: <a' not in r:
                print(prox + ' Good')
                print('Your Ip: ' + r.text)
        except requests.exceptions.ProxyError:
            print(prox + ' Failed')
            pass
    

    身份验证失败意味着您必须使用更多用户名和密码 希望你喜欢它

    【讨论】:

      猜你喜欢
      • 2019-11-17
      • 1970-01-01
      • 2021-04-04
      • 1970-01-01
      • 2021-03-07
      • 2019-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多