From f412f0dc2e9af7bc91f5113d61a44f2d1424c0f2 Mon Sep 17 00:00:00 2001 From: Pavanyogi121 <101347903+Pavanyogi121@users.noreply.github.com> Date: Fri, 23 Sep 2022 23:13:52 +0530 Subject: [PATCH] Update books_selenium.py updated the code as per the latest selenium changes --- books_selenium.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/books_selenium.py b/books_selenium.py index b45baf8..cd42cc4 100644 --- a/books_selenium.py +++ b/books_selenium.py @@ -6,7 +6,8 @@ from selenium.webdriver.common.keys import Keys CHROME_DRIVER_PATH = 'c:/WebDrivers/chromedriver.exe' -HOMEPAGE = "http://books.toscrape.com" +#CHROME_DRIVER_PATH = '/usr/bin/chromedriver' +HOMEPAGE = "https://books.toscrape.com/" def get_data(url, categories): @@ -18,7 +19,8 @@ def get_data(url, categories): driver.implicitly_wait(10) data = [] for category in categories: - humor = driver.find_element_by_xpath(f'//a[contains(text(),{category})]') + # humor = driver.find_element_by_xpath(f'//a[contains(text(),{category})]') + humor = driver.find_element("xpath", f'//a[contains(text(),{category})]') humor.click() try: @@ -29,9 +31,9 @@ def get_data(url, categories): raise e for book in books: - title = book.find_element_by_css_selector("h3 > a") - price = book.find_element_by_css_selector(".price_color") - stock = book.find_element_by_css_selector(".instock.availability") + title = book.find_element(By.CSS_SELECTOR, "h3 > a") + price = book.find_element(By.CSS_SELECTOR, ".price_color") + stock = book.find_element(By.CSS_SELECTOR, ".instock.availability") data.append({ 'title': title.get_attribute("title"), 'price': price.text,