我正在寻找一些帮助让 selenium 使用我的 firefox 配置文件
我找到了我的 firefox 配置文件位置:/root/.mozilla/firefox/abcdefgh.default
import time
import random
import requests
from selenium import webdriver
profile = webdriver.FirefoxProfile()
with open("proxylist.txt") as f:
proxy_list = f.read().splitlines()
proxy_ip, proxy_port = random.choice(proxy_list).split(":")
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", proxy_ip)
profile.set_preference("network.proxy.http_port", int(proxy_port))
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
driver.get("https://www.ipleak.net")
time.sleep(60)
driver.close()
最佳答案
来自 webdriver.FirefoxProfile
的文档:
:args:
profile_directory: Directory of profile that you want to use. This defaults to None and will create a new directory when object is created.
因此,以下应该有效:
profile = webdriver.FirefoxProfile('/root/.mozilla/firefox/abcdefgh.default')
driver = webdriver.Firefox(profile)
关于python - 如何在 selenium 驱动程序 linux python 上设置 firefox 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34075752/