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,