如何解决selenium firefox浏览器被远程控制?

SAL*_*MIN 7 python selenium browser-automation selenium-webdriver geckodriver

我在 Firefox 82.0.3 (64) 中使用 selenium

该代码工作正常,但问题是它说浏览器处于远程控制之下。

有什么办法可以解决或者有其他办法绕过它。

我实际上想要用selenium做的是每次执行代码时使用我定义的新代理打开一个新的firefox实例。

提前致谢

这是我的代码片段。

import webbrowser
import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager 
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

fbgroups = open("all.txt").readlines()
whitelist = open("ntp.txt").readlines()
llf = open('last.txt',"r")

print("Total groups: " + str(len(fbgroups)))
print("Whitelisted: " + str(len(whitelist)))
print("Last: " + str(llf.read()))

# var = int(input('\nStart from: '), 10)
var = 1
myProxy = "us.smartproxy.com:18000"
PROXY_HOST, PROXY_PORT = myProxy.split(":")
while True:
    for a in range (len(fbgroups)-var,0, -1):
        print("Line No: " + str(a+1))
        matched = False

        for b in range (len(whitelist)):
            if whitelist[b].replace('\n', '') in fbgroups[a].replace('\n', ''):
                print("URL"+str(a) + ": Match: " + fbgroups[a])
                matched = True
                break

        if (matched == False):
            lastLink = open('last.txt',"w+")
            lastLink.write(str(len(fbgroups)-a))
            lastLink.close()
        
            print("URL"+ str(a)+ ": " + fbgroups[a])
            
            
            myprofile = webdriver.FirefoxProfile()
            myprofile.set_preference("network.proxy.type", 1)
            myprofile.set_preference("network.proxy.http",PROXY_HOST)
            myprofile.set_preference("network.proxy.http_port",int(PROXY_PORT))
            
            myprofile.set_preference("network.proxy.ssl",PROXY_HOST)
            myprofile.set_preference("network.proxy.ssl_port",int(PROXY_PORT))
            
            myprofile.set_preference("network.proxy.ftp",PROXY_HOST)
            myprofile.set_preference("network.proxy.ftp_port",int(PROXY_PORT))

            user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
            myprofile.set_preference("general.useragent.override", user_agent)
            
            myprofile.update_preferences()
            driver = webdriver.Firefox(firefox_profile=myprofile, executable_path=r'C:\Users\Administrator\Downloads\geckodriver.exe')
            
            driver.get(fbgroups[a])
            print("Page Title is : %s" %driver.title)
            input()

    print("ALL DONE :)")
Run Code Online (Sandbox Code Playgroud)

Sto*_*ica 0

您的浏览器处于远程控制之下,这就是为什么它说它处于远程控制之下。

删除该消息的唯一方法是禁用当前配置文件的远程控制。重置为 false 并重新启动about:configmarionette.enabled

如果您只想设置一个新的配置文件并启动 Firefox,则不需要 selenium。手动创建一个新的配置文件夹,添加prefs.js代理设置,并-profile在启动 Firefox 时传递该选项。