python - 如何在 selenium 驱动程序 linux python 上设置 firefox 配置文件

标签 python selenium

我正在寻找一些帮助让 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/

相关文章:

python - 对数据框最后一行中的所有项目求和

java - 如何在 Java 中使用 Selenium 创建列表然后迭代打印数据

python - 将plot.ly 与 py2exe 一起使用

css - 使用 CSS 选择器选择下拉值

selenium - Selenium 将 DOM 存储在哪里(如果有的话)?

python - 如何使用selenium python点击页面链接

gwt - 我们可以在 GWT 开发模式下运行 selenium 测试吗?

python - 计算一组 "binary strings"中的个数 (Python)

python - 按 pandas 数据框分组的平均值

导入 matplotlib.pyplot 时 Python 崩溃