【问题标题】:Why is Selenium overriding my firefox profile为什么 Selenium 会覆盖我的 Firefox 配置文件
【发布时间】:2020-10-22 11:06:43
【问题描述】:

我正在制作 python selenium 脚本以使用 firefox 自动执行一些谷歌搜索。

我在 Windows 10 64b 上使用 python 3.7。

发生了一些奇怪的事情。当我运行我的 python 脚本时,这很好。 当我用 Nuitka 编译它并运行 exe 时,Firefox 正在打开并添加了一些代理 (127.0.01:53445)。

所以我添加了这一行:

profile.set_preference("network.proxy.type", 0)

同样,脚本运行良好,但当我编译它时,exe 会使用代理打开 Firefox。

这很痛苦,因为这个 127.0.01 代理会造成打开 google 的问题并且我的程序已损坏。

有人已经遇到过这种奇怪的硒行为吗?

【问题讨论】:

  • 你可以跳过 Nuika 并从命令行运行你的 selenium 脚本。
  • 不,我不能,因为我绝对需要编译它以进行分发

标签: python-3.x selenium selenium-webdriver selenium-firefoxdriver nuitka


【解决方案1】:

没有看到您使用的与webdriver 相关的代码,我主要是在这里猜测。我建议也轮换代理。

import requests
from bs4 import BeautifulSoup
from random import choice
firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True

def proxy_generator():
  # REQUIRED - pip install html5lib
  response = requests.get("https://sslproxies.org/")
  soup = BeautifulSoup(response.content, 'html5lib')
  proxy = {'https': choice(list(map(lambda x: x[0] + ':' + x[1], list(zip(map(lambda x: x.text, soup.findAll('td')[::8]), map(lambda x: x.text, soup.findAll('td')[1::8]))))))}
  return proxy

PROXY = proxy_generator()# Commented out proxy option "58.216.202.149:8118"

firefox_capabilities['proxy'] = {
    "proxyType": "MANUAL",
    "httpProxy": PROXY,
    "ftpProxy": PROXY,
    "sslProxy": PROXY
}

driver = webdriver.Firefox(capabilities=firefox_capabilities)

【讨论】:

  • 谢谢,但我不想要任何代理。我需要停用代理。这就是我添加代理类型 0 的原因。
  • @Gauthier Buttez 但如果这在 Nuitka 编译后有效,那么您离我们更近了一步。
  • 感谢@Jortega 提供帮助,但谷歌不喜欢代理。我需要避免代理。
猜你喜欢
  • 2012-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-24
  • 2018-08-15
  • 2015-04-05
  • 2021-04-13
相关资源
最近更新 更多