0% found this document useful (0 votes)
45 views2 pages

From Selenium Import Webdriver

web spraping
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views2 pages

From Selenium Import Webdriver

web spraping
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

from selenium import webdriver

from [Link] import Service as FirefoxService


from webdriver_manager.firefox import GeckoDriverManager
from bs4 import BeautifulSoup

# Spécifier le chemin souhaité pour le téléchargement de GeckoDriver


geckodriver_path = 'C:\\Users\\thaij\\Desktop\\geckodriver-v0.34.0-win32'

# Configurer le WebDriver pour Firefox avec le chemin spécifié


driver = [Link](service=FirefoxService(geckodriver_path))

# URL de la page HTML à récupérer


url = "[Link]

# Ouvrir l'URL dans le navigateur automatisé


[Link](url)

# Attendre que la page se charge complètement


driver.implicitly_wait(10) # Vous pouvez ajuster le temps d'attente selon
vos besoins

# Récupérer le contenu HTML de la page


html_content = driver.page_source

# Utiliser BeautifulSoup pour analyser le contenu HTML


soup = BeautifulSoup(html_content, '[Link]')

# Afficher le HTML de manière formatée


print([Link]())

# Trouver le tableau avec une classe spécifique (ajustez selon le HTML


réel)
table = [Link]('table', {'class': 'table table-striped table-hover'})

if table:
# Extraire les en-têtes du tableau
headers = []
for th in table.find_all('th'):
[Link](th.get_text(strip=True))

# Afficher les en-têtes


print("Headers:", headers)

# Extraire les lignes du tableau


rows = []
for tr in table.find_all('tr')[1:]: # Skip the header row
cells = []
for td in tr.find_all('td'):
[Link](td.get_text(strip=True))
[Link](cells)

# Afficher les lignes


for row in rows:
print(row)
else:
print("Tableau non trouvé.")

# Fermer le navigateur automatisé


[Link]()
from selenium import webdriver
from [Link] import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager
from bs4 import BeautifulSoup

# Configurer le WebDriver pour Firefox avec GeckoDriverManager


geckodriver_path = GeckoDriverManager().install()
driver = [Link](service=FirefoxService(geckodriver_path))

# URL de la page HTML à récupérer


url = "[Link]

# Ouvrir l'URL dans le navigateur automatisé


[Link](url)

# Attendre que la page se charge complètement


driver.implicitly_wait(10) # Vous pouvez ajuster le temps d'attente selon
vos besoins

# Récupérer le contenu HTML de la page


html_content = driver.page_source

# Utiliser BeautifulSoup pour analyser le contenu HTML


soup = BeautifulSoup(html_content, '[Link]')

# Afficher le HTML de manière formatée


#print([Link]())

# Trouver le tableau avec une classe spécifique (ajustez selon le HTML


réel)
table = [Link]('table', {'class': 'table table-striped table-hover'})

if table:
# Extraire les en-têtes du tableau
headers = []
for th in table.find_all('th'):
[Link](th.get_text(strip=True))

# Afficher les en-têtes


print("Headers:", headers)

# Extraire les lignes du tableau


rows = []
for tr in table.find_all('tr')[1:]: # Skip the header row
cells = []
for td in tr.find_all('td'):
[Link](td.get_text(strip=True))
[Link](cells)

# Afficher les lignes


for row in rows:
print(row)
else:
print("Tableau non trouvé.")

# Fermer le navigateur automatisé


[Link]()

You might also like