Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python连接到Tor浏览器_Python_Selenium_Proxy_Tor_Firefox Profile - Fatal编程技术网

如何使用Python连接到Tor浏览器

如何使用Python连接到Tor浏览器,python,selenium,proxy,tor,firefox-profile,Python,Selenium,Proxy,Tor,Firefox Profile,我试图连接到Tor浏览器,但出现了一个错误,说明“proxyConnectFailure”任何想法我尝试了多次尝试了解Tor浏览器的基本知识,以使其连接,但如果有任何帮助,都是徒劳的,可以节省大量时间: from selenium import webdriver from selenium.webdriver.firefox.firefox_profile import FirefoxProfile from selenium.webdriver.firefox.firefox_binary

我试图连接到Tor浏览器,但出现了一个错误,说明“proxyConnectFailure”任何想法我尝试了多次尝试了解Tor浏览器的基本知识,以使其连接,但如果有任何帮助,都是徒劳的,可以节省大量时间:

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


binary = FirefoxBinary(r"C:\Users\Admin\Desktop\Tor Browser\Browser\firefox.exe")
profile = FirefoxProfile(r"C:\Users\Admin\Desktop\Tor Browser\Browser\TorBrowser\Data\Browser\profile.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浏览器,可以使用以下解决方案:

  • 代码块:

    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")
    
  • 浏览器快照:


您可以在中找到相关的讨论

要通过FirefoxProfile连接到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")
    
  • 浏览器快照:


您可以在中找到相关的讨论


我想通过添加Linux对应项来扩展@DebanjanB answer:

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

torexe = os.popen('some/path/tor-browser_en-US/Browser/start-tor-browser') 
# in my case, I installed it under a folder tor-browser_en-US after
# downloading and extracting it from 
# https://www.torproject.org/download/ for linux

profile = FirefoxProfile(
    'some/path/tor-browser_en-US/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()

firefox_options = webdriver.FirefoxOptions()
firefox_options.binary_location = '/usr/bin/firefox' 
# /usr/bin/firefox is default location of firefox - for me anyway

driver = webdriver.Firefox(
    firefox_profile=profile, options=firefox_options, 
    executable_path='wherever/you/installed/geckodriver') 
# I keep my geckodriver(s) in a special folder sorted by versions.
# Geckodriver downloadable here: 
# https://github.com/mozilla/geckodriver/releases/
driver.get("http://check.torproject.org")

我想通过添加Linux对应项来扩展@DebanjanB answer:

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

torexe = os.popen('some/path/tor-browser_en-US/Browser/start-tor-browser') 
# in my case, I installed it under a folder tor-browser_en-US after
# downloading and extracting it from 
# https://www.torproject.org/download/ for linux

profile = FirefoxProfile(
    'some/path/tor-browser_en-US/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()

firefox_options = webdriver.FirefoxOptions()
firefox_options.binary_location = '/usr/bin/firefox' 
# /usr/bin/firefox is default location of firefox - for me anyway

driver = webdriver.Firefox(
    firefox_profile=profile, options=firefox_options, 
    executable_path='wherever/you/installed/geckodriver') 
# I keep my geckodriver(s) in a special folder sorted by versions.
# Geckodriver downloadable here: 
# https://github.com/mozilla/geckodriver/releases/
driver.get("http://check.torproject.org")

可能重复的可能重复的可能重复的仍然相同的错误实际上我正在连接到tor浏览器,但无法访问网站如果您能够连接到url
http://check.torproject.org
并查看此浏览器配置为使用Tor的消息。首先?所以基本上你不是通过Tor连接的。您是否尝试使用答案中的代码块并按原样进行了尝试?是的,我基本上这样做了。当我手动输入时,它会打开tor窗口。它打开了,但没有使用代码。最后,我不得不将sock_端口更改为9150,这进行了欺骗,直到出现相同的错误,实际上我正在连接tor浏览器,但无法访问tor浏览器网站如果您能够连接到url
http://check.torproject.org
并查看此浏览器配置为使用Tor的消息。首先?所以基本上你不是通过Tor连接的。您是否尝试使用答案中的代码块并按原样进行了尝试?是的,基本上我这样做了。当我手动输入时,它会打开tor窗口。它会打开,但不会与代码连接。最后,我必须将sock_端口更改为9150,这就成功了