[FIXED] Die ausführbare Chromedriver-Datei muss sich in PATH befinden

Ausgabe

Ich weiß, dass dies schon oft gefragt wurde und ich habe auch alle Antworten ausprobiert, aber es funktioniert bei mir nicht. Ich habe die Option und die PATH-Methode in einem einfachen Skript ausprobiert, um den Titel einer Webseite zu extrahieren, und es hat funktioniert. aber mit all diesem Code gibt es mir den besagten Fehler

import requests
import pandas as pd
from bs4 import BeautifulSoup
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys

HEADERS = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'}
options = webdriver.ChromeOptions() 
options.add_experimental_option("excludeSwitches", ["enable-logging"])
PATH = r"C:\Users\hp\Downloads\chromedriver\chromedriver.exe"
driver = webdriver.Chrome(options=options , executable_path=PATH)

def get_current_url(url, jobTitle, location):
    driver = webdriver.Chrome()
    driver.get(url)
    time.sleep(3)
    driver.find_element_by_xpath('//*[@Id="text-input-what"]').send_keys(jobTitle)
    time.sleep(3)
    driver.find_element_by_xpath('//*[@Id="text-input-where"]').send_keys(location)
    time.sleep(3)
    driver.find_element_by_xpath('/html/body/div').click()
    time.sleep(3)
    try:
        driver.find_element_by_xpath('//*[@id="jobsearch"]/button').click()
    except:
        driver.find_element_by_xpath('//*[@id="whatWhereFormId"]/div[3]/button').click()
        current_url = driver.current_url
    return current_url

current_url = get_current_url('https://pk.indeed.com/', 'Python Developer', 'Karachi')
print(current_url)
Traceback (most recent call last):
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__      
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1438, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "e:\de-projects\Indeed-scraper.py", line 31, in <module>
    current_url = get_current_url('https://pk.indeed.com/', 'Python Developer', 'Karachi')
  File "e:\de-projects\Indeed-scraper.py", line 15, in get_current_url
    driver = webdriver.Chrome()
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
    super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 89, in __init__
    self.service.start()
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home

Lösung

Lösung

Sie können alle Probleme mit Treibern und Versionen beseitigen, indem Sie verwendenChromeDriverManager

  • Wenn Sie überhaupt ChromeDriverManager – Webdriver Manager for Python verwenden, müssen Sie den nicht explizit herunterladen, ChromeDriverda er automatisch heruntergeladen wird.

  • Wenn Sie das Heruntergeladene verwenden möchten, können ChromeDriverSie die Verwendung vermeiden
    ChromeDriverManager - Webdriver Manager

Mit ChromeDriverManagerkönnen Sie den folgenden Codeblock verwenden:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.maximize_window()
driver.get("https://www.google.com")

Wenn Sie eine bestimmte Version von ChromeDriver herunterladen , können Sie den folgenden Codeblock verwenden:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

s = Service('C:/Users/hp/Downloads/chromedriver/chromedriver.exe')
driver = webdriver.Chrome(service=s)

Hinweis : Wenn Sie sich imLinux / MAC O SXSystem befinden, müssen Sie das Erweiterungsteil entfernen,.exeda es nur fürwindowsPlattformen gilt.


Beantwortet von –
Akzy


Antwort geprüft von –
Terry (FixError Volunteer)

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like