Chromedriver虽然打开了chrome,但没有找到



我正在尝试抓取一个网站来提取一些标签。我已经下载了chromedriver并将其移动到脚本文件夹中。

当我运行下面的脚本时,它会打开chrome并导航到正确的站点。尽管这就是它停止的地方。我已经为chromedriver尝试了许多不同的位置变化

这是下面的脚本:

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)

我得到的错误是:chromedriver' executable needs to be in PATH

您正在调用此

results = driver.find_elements_by_class('cardTitle')

在您关闭驱动器之后。

考虑到这一点,并通过丢失多余的驱动程序初始化,您的脚本应该看起来像:

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

相关内容

最新更新