如何使用Selenium和Python绕过Tor网络设置确认弹出窗口
我正试图通过selenium自动使用Tor浏览器:如何使用Selenium和Python绕过Tor网络设置确认弹出窗口,python,selenium,proxy,tor,firefox-profile,Python,Selenium,Proxy,Tor,Firefox Profile,我正试图通过selenium自动使用Tor浏览器: import time from selenium import webdriver from selenium.webdriver.firefox.firefox_binary import FirefoxBinary binary = '/Applications/TorBrowser.app/Contents/MacOS/firefox' firefox_binary = FirefoxBinary(binary) try: dr
import time
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = '/Applications/TorBrowser.app/Contents/MacOS/firefox'
firefox_binary = FirefoxBinary(binary)
try:
driver = webdriver.Firefox(firefox_binary="/Applications/Tor Browser.app/Contents/MacOS/firefox")
driver.get("https://www.google.com/")
time.sleep(3)
finally:
driver.close()
我正在尝试使用Tor浏览器进行抓取,一切正常,但每次我运行代码时,您都必须手动单击“连接”按钮。如何在selenium中禁用确认屏幕或自动接受 此浏览器配置屏幕
。。。出现,因为您尚未在代码块中明确配置TOR浏览器设置。因此,每次执行程序时,它都会在不使用代理设置的情况下启动新的TOR浏览上下文,并假设您是第一次运行TOR Browser。因此,您将在每次运行时看到Tor网络设置窗口
解决方案 要删除Tor Network Settings(Tor网络设置)窗口,您需要在代码块中配置Tor网络设置,如下所示:
- 代码块:
from selenium import webdriver from selenium.webdriver.firefox.firefox_profile import FirefoxProfile import os torexe = os.popen(r'C:\Users\Soma Bhattacharjee\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe') profile = FirefoxProfile(r'C:\Users\Soma Bhattacharjee\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:\WebDrivers\geckodriver.exe') driver.get("http://check.torproject.org")
- 浏览器快照:
工具书类 您可以在以下内容中找到一些详细的讨论: