我的代码似乎停在“driver = webdriver.Firefox(service=service, options=options)”这一行。 我正在尝试将 selenium 与 tor 浏览器一起使用。不过,我需要它先连接到服务器。
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service
import time
# Set the path to the Tor browser binary
tor_binary_path = 'C:/Users/username/Desktop/Tor Browser/Browser/firefox.exe'
# Create a Firefox options object
options = Options()
# Configure the profile settings
options.set_preference('network.proxy.type', 1)
options.set_preference('network.proxy.socks', '127.0.0.1')
options.set_preference('network.proxy.socks_port', 9150)
# Specify the binary path
options.binary_location = tor_binary_path
# Create a Firefox service with the Tor browser binary path
service = Service(tor_binary_path)
# Create a Firefox webdriver with the Tor browser options and service
print("webdrive")
driver = webdriver.Firefox(service=service, options=options)
# Wait for Tor to connect to its servers
print("wait")
time.sleep(1) # Adjust the sleep duration as needed
# Navigate to google.com
driver.get('https://www.google.com')
print("Done")
我试过擦除 () 里面的东西 例如:“driver = webdriver.Firefox()” 然后 tor 会提示我访问我的站点,但它不会连接到它的服务器。 我如何让它连接到它的服务器并能够使用硒。