【问题标题】:How to initiate Tor Browser using Selenium and Python如何使用 Selenium 和 Python 启动 Tor 浏览器
【发布时间】:2018-10-31 13:40:46
【问题描述】:

我正在尝试使用 Python 在 Tor 浏览器中打开网页

代码:

# Start :Code For TOR Browser
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

# path to TOR binary
binary = FirefoxBinary(r'C:\\Tor Browser\\Browser\\firefox.exe')
# binary = FirefoxBinary(r'C:\\Program Files (x86)\\Vidalia Bridge Bundle\\Tor\\tor.exe')
#path to TOR profile
profile = FirefoxProfile(r'C:\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default')

# cap = DesiredCapabilities().FIREFOX
# cap["marionette"] = False
# driver = webdriver.Firefox(firefox_binary= binary, executable_path="C:\\Python\\scrapy-master\\Projects\\kgooglecom\\WithScreenshot\\geckodriver.exe")

driver = webdriver.Firefox(firefox_profile= profile, firefox_binary= binary, executable_path="C:\\Python\\scrapy-master\\Projects\\kgooglecom\\WithScreenshot\\geckodriver.exe")
# driver = webdriver.Firefox(firefox_profile=profile, firefox_binary= binary, executable_path=r"C:\\Python\\scrapy-master\\Projects\\kgooglecom\\WithScreenshot\\geckodriver.exe")
driver.get("https://www.google.com")
driver.save_screenshot("screenshot1.png")
driver.quit()

# End :Code For TOR Browser

我用this link下载geckodriver

错误:

请建议我如何解决此错误

【问题讨论】:

    标签: python selenium proxy tor firefox-profile


    【解决方案1】:

    要使用 Python 通过 Tor 浏览器 打开网页,您可以使用 Firefox 配置文件tor 守护进程您可以使用以下解决方案:

    • 代码块:

      from selenium import webdriver
      from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
      import os
      
      torexe = os.popen(r'C:\Users\AtechM_03\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe')
      profile = FirefoxProfile(r'C:\Users\AtechM_03\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'C:\Utility\BrowserDrivers\geckodriver.exe')
      driver.get("http://check.torproject.org")
      
    • 浏览器快照:

    【讨论】:

    • 你知道如何避免打开 Tor,而是让它在后台运行吗?
    猜你喜欢
    • 2013-06-11
    • 2017-01-01
    • 1970-01-01
    • 2020-10-21
    • 2016-03-22
    • 2020-07-31
    • 1970-01-01
    • 2020-10-18
    • 2017-01-01
    相关资源
    最近更新 更多