Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #code snippet 7
- from selenium import webdriver
- from selenium.webdriver.common.by import By
- from selenium.webdriver.firefox.options import Options
- # the target website
- url = "https://scrapeme.live/shop/"
- #the interface for turning on headless mode
- options = Options()
- options.add_argument("-headless")
- #using Firefox headless webdriver to secure connection to Firefox
- with webdriver.Firefox(options=options) as driver:
- #opening the target website in the browser
- driver.get(url)
- print("Page URL:", driver.current_url)
- print("Page Title:", driver.title)
- #using Selenium's find_elements() API to find the parent element
- animal_clones = driver.find_elements(By.XPATH, "//a[@class='woocommerce-LoopProduct-link woocommerce-loop-product__link']")
- #using Selenium's find_element() API to locate each of the child elements
- for animal in animal_clones:
- animal_name = animal.find_element(By.XPATH, ".//h2")
- animal_price = animal.find_element(By.XPATH, ".//span")
- #parsing the extracted data into a python dictionary
- clones = {
- "name": animal_name.text,
- "price": animal_price.text
- }
- print(clones)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement