Skip to content

Instantly share code, notes, and snippets.

@germainlefebvre4
Created September 29, 2018 22:36
Show Gist options
  • Save germainlefebvre4/da64c365d42dae20f0fe8cb09359b0f8 to your computer and use it in GitHub Desktop.
Save germainlefebvre4/da64c365d42dae20f0fe8cb09359b0f8 to your computer and use it in GitHub Desktop.
Selenium Python - Parse Auchan Products with configurable sotres and products
#!/usr/bin/python3
import re
from selenium import webdriver
list_stores = [
"https://www.auchandrive.fr/drive/mag/update-924",
]
list_products = [
"https://www.auchandrive.fr/catalog/coca-cola-zero-1l-P762493",
]
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
try:
driver = webdriver.Chrome('chromedriver', chrome_options=chrome_options, service_args=['--verbose', '--log-path=/tmp/chromedriver.log'])
for store_url in list_stores:
driver.get(store_url)
print("Visit Auchan Drive Englos")
for product_url in list_products:
PRODUCT_NAME_SELECTOR = './/p[@class="pdp-infos__title"]'
PRODUCT_PRICE_SELECTOR = './/p[@class="price-standard"]'
PRODUCT_PRICEPER_SELECTOR = './/p[@class="price--per"]'
driver.get(product_url)
print(driver.title)
product_name = driver.find_element_by_xpath(PRODUCT_NAME_SELECTOR).text
product_price = "".join(driver.find_element_by_xpath(PRODUCT_PRICE_SELECTOR).text).replace("\u20ac", "").replace(" ", "")
product_priceper = re.sub(r" \u20ac.*", "", driver.find_element_by_xpath(PRODUCT_PRICEPER_SELECTOR).text).replace(" ", "")
print("%s - %s - %s" % (product_name, product_price, product_priceper))
finally:
driver.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment