Skip to content
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

deprecation update #2

Open
wants to merge 3 commits 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
14 changes: 8 additions & 6 deletions books_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

CHROME_DRIVER_PATH = 'c:/WebDrivers/chromedriver.exe'
# CHROME_DRIVER_PATH = 'chromedriver.exe'
HOMEPAGE = "http://books.toscrape.com"


def get_data(url, categories):
browser_options = ChromeOptions()
browser_options.headless = True

driver = Chrome(executable_path=CHROME_DRIVER_PATH, options=browser_options)
driver = Chrome(service=Service(ChromeDriverManager().install()))
driver.get(url)
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.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