Skip to content

Update books_selenium.py #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions books_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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,
Expand Down