Python:Selenium网络驱动程序Chrome打开浏览器,但不打开所选网站



我刚刚下载了Anaconda(v1.7.2(和spyder(Python 3.7.6(。我有chrome(版本81.0.4044.92 64位(Selenium 3.141.0版

当我写下面的代码时,我得到的响应是chrome打开了一个新的实例和一个选项卡,但只有起始页,它从未打开我指出的网站。我也尝试过关闭所有其他chrome实例,但没有帮助。我已将以下内容添加到系统环境变量中C: \Users\aaa.bbb\Anaconda3\Scripts;c: \users\aaa.bbb\anaconda3\lib\site packages\chromedriver;


from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
import time
driver = webdriver.Chrome("C:Program Files (x86)GoogleChromeApplicationchrome.exe")
driver.get('http://www.aftonbladet.se');
time.sleep(3)
driver.quit()

我在spyder中得到的响应是:

runfile('C:/Users/aaa.bbb/.spyder-py3/temp.py', wdir='C:/Users/aaa.bbb/.spyder-py3')
Traceback (most recent call last):
File "C:Usersaaa.bbb.spyder-py3temp.py", line 8, in <module>
driver = webdriver.Chrome("C:Program Files (x86)GoogleChromeApplicationchrome.exe")
File "C:Usersaaa.bbbAnaconda3libsite-packagesseleniumwebdriverchromewebdriver.py", line 73, in __init__
self.service.start()
File "C:Usersaaa.bbbAnaconda3libsite-packagesseleniumwebdrivercommonservice.py", line 98, in start
self.assert_process_still_running()
File "C:Usersaaa.bbbAnaconda3libsite-packagesseleniumwebdrivercommonservice.py", line 111, in assert_process_still_running
% (self.path, return_code)
WebDriverException: Service C:Program Files (x86)GoogleChromeApplicationchrome.exe unexpectedly exited. Status code was: 0

请下载最新的chrome驱动程序,该驱动程序支持您的浏览器版本:你可以从这里下载最新的Chrome驱动程序,这里r表示相对路径::

from selenium import webdriver
driver = webdriver.Chrome(executable_path=r" path to your chromedriver.exe")
driver.maximize_window()
baseUrl = "https://www.google.com"
driver.get(baseUrl)

您需要使用Chrome Web驱动程序,而不是使用实际的Chrome应用程序。下载适用于Windows的Chrome网络驱动程序。

编辑此行以在下载后指向Web驱动程序。

driver = webdriver.Chrome("C:Program Files (x86)GoogleChromeApplicationchrome.exe")