Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未安装Python Selenium Chrome Web驱动程序_Python_Selenium_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

未安装Python Selenium Chrome Web驱动程序

未安装Python Selenium Chrome Web驱动程序,python,selenium,selenium-webdriver,selenium-chromedriver,Python,Selenium,Selenium Webdriver,Selenium Chromedriver,我正在尝试自动安装最新版本的Chrome驱动程序,然后将其用于我的脚本,但遇到了错误。你有没有想到这里出了什么问题?我的缓存有问题吗 driver2 = webdriver.Chrome(ChromeDriverManager().install()) options = selenium.webdriver.ChromeOptions() #options.add_argument('headless') options.add_argument('window-size=1920x1080'

我正在尝试自动安装最新版本的Chrome驱动程序,然后将其用于我的脚本,但遇到了错误。你有没有想到这里出了什么问题?我的缓存有问题吗

driver2 = webdriver.Chrome(ChromeDriverManager().install())
options = selenium.webdriver.ChromeOptions()
#options.add_argument('headless')
options.add_argument('window-size=1920x1080')
driver = webdriver.Chrome(driver2, options=options)
错误:

[WDM] - Looking for [chromedriver 89.0.4389.23 win32] driver in cache 
[WDM] - File found in cache by path [C:\Users\xxx\.wdm\drivers\chromedriver\89.0.4389.23\win32\chromedriver.exe]
Traceback (most recent call last):
  File "C:\Users\xxx\Python\Price Tracking\Real Estate\RealEstate-Scraping.py", line 60, in <module>
    driver = webdriver.Chrome(driver2, options=options)
  File "C:\Python38\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Python38\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Python38\lib\subprocess.py", line 1247, in _execute_child
    args = list2cmdline(args)
  File "C:\Python38\lib\subprocess.py", line 549, in list2cmdline
    for arg in map(os.fsdecode, seq):
  File "C:\Python38\lib\os.py", line 818, in fsdecode
    filename = fspath(filename)  # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not WebDriver
[WDM]-正在缓存中查找[chromedriver 89.0.4389.23 win32]驱动程序
[WDM]-通过路径[C:\Users\xxx\.WDM\drivers\chromedriver\89.0.4389.23\win32\chromedriver.exe]在缓存中找到的文件
回溯(最近一次呼叫最后一次):
文件“C:\Users\xxx\Python\Price Tracking\Real Estate\Real Estate Scraping.py”,第60行,在
driver=webdriver.Chrome(driver2,options=options)
文件“C:\Python38\lib\site packages\selenium\webdriver\chrome\webdriver.py”,第73行,在\uuu init中__
self.service.start()
文件“C:\Python38\lib\site packages\selenium\webdriver\common\service.py”,第72行,在开始处
self.process=subprocess.Popen(cmd,env=self.env,
文件“C:\Python38\lib\subprocess.py”,第854行,在\uuu init中__
self.\u execute\u child(参数、可执行文件、预执行文件、关闭文件、,
文件“C:\Python38\lib\subprocess.py”,第1247行,在执行子进程中
args=list2cmdline(args)
文件“C:\Python38\lib\subprocess.py”,第549行,在list2cmdline中
对于映射中的arg(os.fsdecode,seq):
文件“C:\Python38\lib\os.py”,第818行,在fsdecode中
filename=fspath(filename)#对“filename”进行类型检查。
TypeError:应为str、bytes或os.PathLike对象,而不是WebDriver

driver=webdriver.Chrome(driver2,options=options)

您正在将WebDriver对象作为位置参数发送


WebDriver的第一个参数是可执行路径。

您需要告诉WebDriver的路径:

webdriver.chrome(可执行文件路径=*path*,选项=选项)

但是
driver2=webdriver.Chrome(ChromeDriverManager().install())
创建selenium的新实例

应该使用您的用例-代码的第一行不是必需的

请注意,“无头”也需要“在它前面”

完整代码:

options = selenium.webdriver.ChromeOptions()
#options.add_argument('--headless')
#could also do options.headless = True
options.add_argument('--window-size=1920x1080')
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
driver.get('enterwebsite.ext')
#do other stuff
试一试:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
options.add_argument('--headless')
options.add_argument('--window-size=1920,1080')
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)

driver.get('https://google.com')

driver.quit()
将参数选项传递给webdriver时,请将其设置在初始化上方,并将其放入chrome()中,如下所示:

options = Options()
options.add_argument('--headless')
options.add_argument('--window-size=1920,1080')
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
最后初始化驱动程序

options = Options()
options.add_argument('--headless')
options.add_argument('--window-size=1920,1080')
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)