繁体   English   中英

如何使用Selenium和Python启动Tor浏览器

[英]How to initiate Tor Browser using Selenium and Python

我正在尝试使用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

我使用此链接下载geckodriver

错误:

在此处输入图片说明

请建议我如何解决此错误

要使用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_Browser

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM