英文:
Selenium cant get or interact with custom profile after cookies sent (and other common solutions)?
问题
#profile
chrome_options.add_argument(r"user-data-dir=C:\Users\prodi\AppData\Local\Google\Chrome\User Data\Profile 2")
#Path to your chrome profile
service = ChromeService(executable_path=r'C:\Program Files (x86)\Google\Chrome\Application\chrome.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"))
你好,我正在尝试使用我的Google配置文件访问一个网址,但它不起作用。Chrome配置文件弹出,但不执行任何操作。过一段时间后,它只会给出一个无法连接的错误。
以下是你提供的错误信息:
Traceback (most recent call last):
File "c:\Users\prodi\Desktop\auto job applying bot\auto-job-applying-bot\Test Code\main.py", line 52, in <module>
driver = webdriver.Chrome(service=service,options=chrome_options)
File "C:\Users\prodi\Desktop\auto job applying bot\auto-job-applying-bot\env\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 80, in __init__
super().__init__(
File "C:\Users\prodi\Desktop\auto job applying bot\auto-job-applying-bot\env\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 101, in __init__
self.service.start()
File "C:\Users\prodi\Desktop\auto job applying bot\auto-job-applying-bot\env\lib\site-packages\selenium\webdriver\common\service.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)\Google\Chrome\Application\chrome.exe
我尝试了很多解决方案:
首先,请确保路径是正确的。它们看起来是正确的(https://i.stack.imgur.com/hO50z.jpg)。
其次,有一个解决方案建议使用一个Cookie,但没有起作用(https://stackoverflow.com/questions/71052074/selenium-get-not-working-with-custom-google-profile)。
其他解决方案也没有解决问题。你认为问题出在哪里?
英文:
#profile
chrome_options.add_argument(r"user-data-dir=C:\Users\prodi\AppData\Local\Google\Chrome\User Data\Profile 2")
#Path to your chrome profile
service = ChromeService(executable_path=r'C:\Program Files (x86)\Google\Chrome\Application\chrome.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"))
Hello I am trying to go to a url with my google profile. It isnt working. The chrome profile pops up but it dosent do anything. After a while it just gives me a cant connect error.
this:
Traceback (most recent call last):
File "c:\Users\prodi\Desktop\auto job applying bot\auto-job-applying-bot\Test Code\main.py", line 52, in <module>
driver = webdriver.Chrome(service=service,options=chrome_options)
File "C:\Users\prodi\Desktop\auto job applying bot\auto-job-applying-bot\env\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 80, in __init__
super().__init__(
File "C:\Users\prodi\Desktop\auto job applying bot\auto-job-applying-bot\env\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 101, in __init__
self.service.start()
File "C:\Users\prodi\Desktop\auto job applying bot\auto-job-applying-bot\env\lib\site-packages\selenium\webdriver\common\service.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)\Google\Chrome\Application\chrome.exe
I tried many solutions
first is to make sure paths are right. They are looking https://i.stack.imgur.com/hO50z.jpg
second this:
one solution says to use a cookie. did nothing https://stackoverflow.com/questions/71052074/selenium-get-not-working-with-custom-google-profile
the others also do noting what is wrong?
答案1
得分: 1
The issue seems to be stemming from this line:
service = ChromeService(executable_path=r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe')
driver = webdriver.Chrome(service=service,options=chrome_options)
因为您正在使用 Chrome 浏览器可执行文件创建 ChromeService 实例,尽管您应该使用 Chromedriver 可执行文件。请参阅相关的 文档。 <br>
A fix for this that I would recommend you to do, since it's a pain to always manually upgrade your Chromedriver version whenever your Chrome Browser updates would be to use the webdriver-manager package. The code would then look like this:
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)
英文:
The issue seems to be stemming from this line:
service = ChromeService(executable_path=r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe')
driver = webdriver.Chrome(service=service,options=chrome_options)
Because you are creating a ChromeService instance with the Chrome browser executable, even though you should be using the Chromedriver executable. See relevant docs. <br>
A fix for this that I would recommend you to do, since it's a pain to always manually upgrade your Chromedriver version whenever your Chrome Browser updates would be to use the webdriver-manager package.
The code would then look like this:
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install(), options=chrome_options)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论