我正在编写一个脚本来使用多线程代理访问网站,但现在我卡在多线程中,当我运行下面的脚本时,它打开了 5 个浏览器,但所有 5 个浏览器都使用 1 个代理,我希望 5 个浏览器使用不同的代理,有人可以帮我完成吗?谢谢你
这是我的脚本:
from selenium import webdriver
from selenium import webdriver
import time , random
import threading
def e():
a = open("sock2.txt", "r")
for line in a.readlines():
b = line
prox = b.split(":")
IP = prox[0]
PORT = int(prox[1].strip("\n"))
print(IP)
print(PORT)
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.socks", IP)
profile.set_preference("network.proxy.socks_port", PORT)
try:
driver = webdriver.Firefox(firefox_profile=profile)
driver.get("http://www.whatsmyip.org/")
except:
print("Proxy Connection Error")
driver.quit()
else:
time.sleep(random.randint(40, 70))
driver.quit()
for i in range(5):
t = threading.Thread(target=e)
t.start()
Run Code Online (Sandbox Code Playgroud)
(祝大家新年快乐,万事如意)