硒不能得到或与自定义配置文件后发送cookie(和其他常见的解决方案)?



#profile
chrome_options.add_argument(r"user-data-dir=C:UsersprodiAppDataLocalGoogleChromeUser DataProfile 2") 
#Path to your chrome profile
service = ChromeService(executable_path=r'C:Program Files (x86)GoogleChromeApplicationchrome.exe')
driver = webdriver.Chrome(service=service,options=chrome_options)
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
#get url
tempUrl = "https://www.indeed.com/jobs?q=Web+Dev+Intern&l=Remote&sc=0kf%3Aattr%28DSQF7%29explvl%28ENTRY_LEVEL%29%3B&rbl=Remote&jlid=aaa2b906602aa8f5&pp=gQAAAAABhyaEcDMAAAAB_d4VZAADAAABAAA&vjk=e8d531753a776d38"
driver.get(tempUrl)
pickle.dump(driver.get_cookies(), open("cookies.pkl", "wb"))

你好,我正试图去一个url与我的谷歌个人资料。这行不通。chrome配置文件弹出,但它不做任何事情。过了一会儿,它只是给我一个不能连接错误。

:

Traceback (most recent call last):
File "c:UsersprodiDesktopauto job applying botauto-job-applying-botTest Codemain.py", line 52, in <module>
driver = webdriver.Chrome(service=service,options=chrome_options)
File "C:UsersprodiDesktopauto job applying botauto-job-applying-botenvlibsite-packagesseleniumwebdriverchromewebdriver.py", line 80, in __init__    
super().__init__(
File "C:UsersprodiDesktopauto job applying botauto-job-applying-botenvlibsite-packagesseleniumwebdriverchromiumwebdriver.py", line 101, in __init__ 
self.service.start()
File "C:UsersprodiDesktopauto job applying botauto-job-applying-botenvlibsite-packagesseleniumwebdrivercommonservice.py", line 113, in start        
raise WebDriverException(f"Can not connect to the Service {self.path}")      
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service C:Program Files (x86)GoogleChromeApplicationchrome.exe

我试了很多方法

首先是确保路径是正确的。他们正在寻找https://i.stack.imgur.com/hO50z.jpg

第二:一种解决方案是使用cookie。Selenium: get()无法使用自定义google配置文件

别人也不做什么是错的?

问题似乎源于这一行:

service = ChromeService(executable_path=r'C:Program Files (x86)GoogleChromeApplicationchrome.exe')
driver = webdriver.Chrome(service=service,options=chrome_options)

因为你正在用Chrome浏览器可执行文件创建一个ChromeService实例,即使你应该使用Chromedriver可执行文件。请参阅相关文档。
我建议你这样做,因为每当你的Chrome浏览器更新将使用webdriver-manager包时,总是手动升级你的Chromedriver版本是一种痛苦。代码看起来像这样:

from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)

相关内容

最新更新