简体   繁体   中英

Chromedriver is not found although it opens chrome

I am trying to scrape a site to extract some tags. I have downloaded chromedriver and moved it to the script folder.

When I run the below script, it opens chrome and navigates to the correct site. Although that is where it stops. I have tried numerous different variations of locations for the chromedriver

This is the script below:

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


DRIVER_PATH = '/Users/jasonbeedle/Desktop/snaviescraper/chromedriver'
driver = webdriver.Chrome(executable_path=DRIVER_PATH)
driver.get('https://www.canalplus.com/programme-tv/')

options = Options()
options.page_load_strategy = 'normal'
driver = webdriver.Chrome(options=options)

# Navigate to url
driver = webdriver.Chrome(options=options, executable_path=DRIVER_PATH)
driver.get("https://www.canalplus/programme-tv")
driver.quit

results = driver.find_elements_by_class(
    'cardTitle')

print(results.text)

The error I get is: chromedriver' executable needs to be in PATH

You are calling this

results = driver.find_elements_by_class('cardTitle')

after you already closed the driver.

With that in mind, and by losing superfluous driver initializations, your script should look something like:

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

DRIVER_PATH = '/Users/jasonbeedle/Desktop/snaviescraper/chromedriver'

options = Options()
options.page_load_strategy = 'normal'

# Navigate to url
driver = webdriver.Chrome(options=options, executable_path=DRIVER_PATH)
driver.get("https://www.canalplus/programme-tv")


results = driver.find_elements_by_class(
    'cardTitle')

print(results.text)

driver.quit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM