編輯&添加下面的代碼: 我的主要問題是我在文件1 &用戶代理文件的代理2 &我改變他們都在同一時間,但現在我想隨機選擇改變兩者&送他們個人資料.set_preference(),但它只是隨機選擇1個代理,然後每次都使用同一個代理。請有人幫助我如何選擇隨機代理以及用戶代理,拆分代理,然後將它們發送到配置文件?如何通過文本文件獲取隨機文本和循環,直到它隨機獲取所有文本1?1。
def change():
fi = open("C:\\UsersDesktop\\text_file1.txt","r")
file1 = random.choice(fi.readlines())
print(file1)
fi2 = open("C:\\Users\\Desktop\\text_file2.txt","r")
file2 = fi2.read().splitlines()
for p, a in zip(file, file2):
print(p)
IP,PORT = urls.strip().split(':')
print(file1)
try:
print("Trying proxy {0}" .format(p))
print("Brwoser Agent {0}" .format(a))
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", IP)
profile.set_preference("network.proxy.http_port", int(PORT))
profile.set_preference("network.proxy.ssl", IP)
profile.set_preference("network.proxy.ssl_port", int(PORT))
profile.set_preference("network.proxy.ftp", IP)
profile.set_preference("network.proxy.ftp_port", int(PORT))
profile.set_preference("general.useragent.override",'{0}'.format(a))
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
#driver.set_window_position(-2000, 0)
driver.get("https://www.whatismyiaddress.com")
print('Program will pause for 1 min 40 sec')
time.sleep(100)
driver.quit()
except:
print('This is not working : %s' % p)
print("next try in 5 seconds")
time.sleep(5)
driver.quit()
print('Nothing left to try')
你需要發佈一些代碼,所以你可以嘗試匿名你擁有和發佈的內容。 – quamrana