【问题标题】:Chromedriver not getting detected in python在 python 中未检测到 Chromedriver
【发布时间】:2021-10-31 18:58:17
【问题描述】:

我正在尝试运行一个 selenium 脚本,但它无法检测到 chromedriver 任何人都可以在我尝试运行它时帮我解决这个问题,它给了我一个错误,指出 chromedriver 在特定路径中不存在但是我已下载并保存在特定路径上 以下是快照和代码供参考。

booking.py

import booking.constants as const
from selenium import webdriver


class Booking(webdriver.Chrome):
    def __init__(self , driver_path = "C:\\chromedriver.exe"):
        self.driver_path = driver_path
        super(Booking, self).__init__()

    
    def land_first_page(self):
        self.get(const.BASE_URL)

run.py //在我的编辑器中运行这个python文件

from booking.booking import Booking

inst = Booking()
inst.land_first_page()

【问题讨论】:

  • 也许尝试将 chromedriver.exe 移动到桌面并写入确切的路径“C:\Users\Desktop\chromedriver.exe”。
  • 得到一个新的错误文件 "c:\Users\Anshul Thakur\Desktop\Selenium Python\Bot\booking\booking.py",第 6 行 def __init__(self , driver_path = "C:\Users \Desktop\chromedriver.exe"): ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape PS C:\Users\Anshul Thakur\Desktop\Selenium Python\Bot >

标签: python selenium selenium-chromedriver undetected-chromedriver


【解决方案1】:

尝试插入chromedriver所在位置的整个方向路径,也不要忘记使用双斜杠,“C:\Users\desktop\...”整个路径。

编辑 去寻找你正在使用的谷歌浏览器的版本,然后检查你的chromedriver的版本,如果它们不一样那就是错误,尝试安装与你的google chrome版本相同的chromedriver版本

【讨论】:

  • 尝试得到与我最初遇到的相同的错误
  • @AnshulThakur 我编辑了我的答案,希望对您有所帮助
  • 试过了也没有运气
【解决方案2】:

复制 Chromedriver.exe 文件并粘贴您的 CODE 目录

那么

import booking.constants as const
from selenium import webdriver

class Booking(webdriver.Chrome):
    def __init__(self , driver_path = "chromedriver.exe"):
        self.driver_path = driver_path
        super(Booking, self).__init__()


def land_first_page(self):
    self.get(const.BASE_URL

看起来像。 chromedriver.exe 文件必须与您的脚本文件所在的目录相同

【讨论】:

  • 我没明白你的意思是说只放 chromedriver.exe 而不是它所在的整个路径???
  • 如果您将“chromedriver.exe”存储在代码文件夹中,则无需提及完整路径,只需提及 chromedriver.exe 即可
  • 你能给我一个参考或关于如何做到这一点的东西吗??
  • 我编辑了 ans 并附上了图片。现在试试
  • 是的,明白了,谢谢凯斯法希姆
【解决方案3】:

将您的chromedriver.exe 文件复制到您当前path 的文件夹中,以显示您可以使用的当前路径:

import sys
print(sys.path)

请务必使用与浏览器相同的 chromedriver 版本

https://chromedriver.chromium.org/downloads

【讨论】: