【问题标题】:Setting up tor with selenium web driver. (Windows)使用 selenium web 驱动程序设置 tor。 (视窗)
【发布时间】:2019-09-07 18:22:57
【问题描述】:

我尝试使用 selenium 设置我的 tor,但它不断抛出异常。

我已尝试设置二进制文件和配置文件,但没有成功。

from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
import os

torexe = os.popen(r'C:\Users\Jawad Ahmad Khan\Desktop\Tor Browser\Browser\firefox.exe')
profile = FirefoxProfile(r'C:\Users\Jawad Ahmad Khan\Desktop\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default')
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', '127.0.0.1')
profile.set_preference('network.proxy.socks_port', 9050)
profile.set_preference("network.proxy.socks_remote_dns", False)
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile= profile, 
executable_path=r'D:\geckodriver\geckodriver.exe')
driver.get("http://check.torproject.org")

这是错误信息:

selenium.common.exceptions.WebDriverException: Message: Reached error page: about:neterror?e=proxyConnectFailure&u=https%3A//check.torproject.org/&c=UTF-8&f=regular&d=Firefox%20is%20configured%20to%20use%20a%20proxy%20server%20that%20is%20refusing%20connections.

【问题讨论】:

  • 你有正确的端口吗?默认值为 9150。
  • 你能解释一下吗。
  • 检查 -- tor:about:preferences:network proxy:settings:sock port
  • 当你发出这个 selenium 请求时,tor 是否在你的系统上运行?
  • 是的 tor 正在我的系统上运行,浏览器实例打开但出现此错误的超时异常。

标签: python-3.x selenium-webdriver tor


【解决方案1】:

这适用于我的 Mac 与 Chrome 和 Tor。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

def get_chrome_webdriver():

  tor_proxy = "127.0.0.1:9150"

  chrome_options = Options()
  chrome_options.add_argument("--test-type")
  chrome_options.add_argument('--ignore-certificate-errors')
  chrome_options.add_argument('--disable-extensions')
  chrome_options.add_argument('disable-infobars')
  chrome_options.add_argument("--incognito")
  chrome_options.add_argument('--proxy-server=socks5://%s' % tor_proxy)

  driver = webdriver.Chrome('/usr/local/bin/chromedriver', options=chrome_options)

  return driver

def get_chrome_browser(url):
  browser = get_chrome_webdriver()
  browser.get(url)

  return browser


get_chrome_browser('https://check.torproject.org/')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-22
    • 2018-07-15
    • 1970-01-01
    • 1970-01-01
    • 2021-01-04
    • 1970-01-01
    • 2012-07-06
    • 1970-01-01
    相关资源
    最近更新 更多