簡體   English   中英

如何使用 nordvpn 服務器作為 python 請求的代理?

[英]How to use nordvpn servers as proxy for python requests?

我正在嘗試使用 nordvpn 為 python 請求創建代理列表,但我似乎無法確定將服務器編寫為代理的正確格式。

據我了解,以該服務器為例,格式是這樣的:

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

我嘗試了各種組合:

  1. 我的登錄名 email 和密碼
  2. 我的 nordvpn 帳戶用戶名和密碼
  3. 我意識到並非所有服務器都可以用作代理,所以我確保它們是
  4. 我嘗試使用 udp/tcp 而不是 http/https

這些嘗試都沒有奏效,我真的希望有人能告訴我正確的方法。

這是我制作的一個簡單腳本:

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

驗證失敗意味着您必須使用更多的用戶名和密碼希望您喜歡它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM