我如何修复我的代码,因为我不能让我的浏览器请求通过这些代理和头?

2024-04-26 13:54:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经让我的代码卸载了一个带有代理的txt文件,但似乎不明白为什么它没有被用作代理,以及当代理工作时,头不让代理工作

需要知道的事情:

我用Grabify查看我的头和ip/端口。 大多数未使用的导入来自其他测试。 感谢您的帮助

 import urllib3, json, re, requests, random, os, subprocess as sp, time 

#imports ip:port from txt
proxies=[]
with open("C:\\Users\\David\\Downloads\\proxies.txt") as file:
    for line in file:
        ip = re.findall(r'[0-9]+(?:\.[0-9]+){3}:[0-9]+', line)
        proxies.append(ip)
    print("Proxies Gathered From List....")

#browser Function
def browse(url, ip):
    browser = ['C:\Program Files (x86)\Google\Chrome\Application\chrome', url,
    '--proxy-server={ip}'.format(ip=ip)]
    #'--user-agent=(Mozilla/15.2 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106     Safari/537.36)']

    browserr = sp.Popen(browser)
    time.sleep(1)
    browserr.terminate()

#Testing
url_link = "https://grabify.link/YKM49H"
FinIP=proxies[int(random.randint(1,len(proxies)-1))]
print(*FinIP)
browse(url_link, *FinIP)

目标:

尝试在google chrome中打开带有代理的链接;自定义标题


Tags: ipbrowserretxturl代理timeas