如何使用 Python 连接到 Tor 浏览器 [英] How to connect to Tor browser using Python

查看:31
本文介绍了如何使用 Python 连接到 Tor 浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到 Tor 浏览器,但收到一条错误消息,指出proxyConnectFailure" 我尝试了多次尝试进入 Tor 浏览器的基础知识以使其连接,但如果有任何可以帮助生活的想法,那么一切都是徒劳的节省了大量时间:

I am trying to connect to a Tor browser but get an error stating "proxyConnectFailure" any ideas I have tried multiple attempts to get into the basics of Tor browser to get it connected but all in vain if any could help life could be saved big time:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary


binary = FirefoxBinary(r"C:UsersAdminDesktopTor BrowserBrowserfirefox.exe")
profile = FirefoxProfile(r"C:UsersAdminDesktopTor BrowserBrowserTorBrowserDataBrowserprofile.default")

# Configured profile settings.

proxyIP = "127.0.0.1"
proxyPort = 9150

proxy_settings = {"network.proxy.type":1,
    "network.proxy.socks": proxyIP,
    "network.proxy.socks_port": proxyPort,
    "network.proxy.socks_remote_dns": True,
}
driver = webdriver.Firefox(firefox_binary=binary,proxy=proxy_settings)

def interactWithSite(driver):

    driver.get("https://www.google.com")    
    driver.save_screenshot("screenshot.png")

interactWithSite(driver)

推荐答案

要通过 FirefoxProfile 连接到 Tor 浏览器,您可以使用以下解决方案:

To connect to a Tor Browser through a FirefoxProfile you can use the following solution:

  • 代码块:

  • Code Block:

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

torexe = os.popen(r'C:UsersAtechM_03DesktopTor BrowserBrowserTorBrowserTor	or.exe')
profile = FirefoxProfile(r'C:UsersAtechM_03DesktopTor BrowserBrowserTorBrowserDataBrowserprofile.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:UtilityBrowserDriversgeckodriver.exe')
driver.get("http://check.torproject.org")

  • 浏览器快照:

  • Browser Snapshot:

    您可以在中找到相关讨论如何通过 Selenium 在 Chrome 浏览器中使用 Tor

    这篇关于如何使用 Python 连接到 Tor 浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆