Advertisement
Temidayo12

Firefox 7

Jan 13th, 2023 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. #code snippet 7
  2. from selenium import webdriver
  3. from selenium.webdriver.common.by import By
  4. from selenium.webdriver.firefox.options import Options
  5.  
  6. # the target website
  7. url = "https://scrapeme.live/shop/"
  8.  
  9. #the interface for turning on headless mode
  10. options = Options()
  11. options.add_argument("-headless")
  12.  
  13. #using Firefox headless webdriver to secure connection to Firefox
  14. with webdriver.Firefox(options=options) as driver:
  15.  
  16.      #opening the target website in the browser
  17.     driver.get(url)
  18.  
  19.    
  20.     print("Page URL:", driver.current_url)
  21.     print("Page Title:", driver.title)
  22.    
  23.     #using Selenium's find_elements() API to find the parent element
  24.     animal_clones = driver.find_elements(By.XPATH, "//a[@class='woocommerce-LoopProduct-link woocommerce-loop-product__link']")
  25.    
  26.     #using Selenium's find_element() API to locate each of the child elements
  27.     for animal in animal_clones:
  28.         animal_name = animal.find_element(By.XPATH, ".//h2")
  29.         animal_price = animal.find_element(By.XPATH, ".//span")
  30.        
  31.         #parsing the extracted data into a python dictionary
  32.         clones = {
  33.             "name": animal_name.text,
  34.             "price": animal_price.text
  35.         }
  36.  
  37.         print(clones)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement