Mis à jour le Sept. 20, 2022, 5:48 a.m.
Article à venir
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
web="www.google.com"
path='introduce chromedriver path'
service = Service(executable_path=path)
driver = webdriver.Chrome(service=service)
driver.get(web)
# Find an element
driver.find_element(by="id", value="...")
# Find elements
driver.find_elements(by="xpath", value="...") # returns a list
#Quit driver
driver.quit()
# Getting the text
data = element.text
# simuler un comportement humain en mettant des temps d'attente
# Implicit Waits
import time
time.sleep(2)
#Explicit Waits
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.ID, 'id_name')))
# Wait 5 seconds until an element is clickable
# Options: Headless mode, change window size
from selenium.webdriver.chrome.options import Options
options = Options()
options.headless = True
options.add_argument('window-size=1920x1080')
driver = webdriver.Chrome(service=service, options=options