5.5 extracting_data_from_a_table.py
Wed Jan 31 2024 19:49:52 GMT+0000 (Coordinated Universal Time)
Saved by
@mnis00014
#python
#selenium
#scraping
# --------------------------- Chrome ---------------------------------
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
path = r"C:\Drivers\chromedriver-win64\chromedriver.exe"
website = "https://www.adamchoi.co.uk/overs/detailed"
# Use the Service class to specify the path to chromedriver.exe
service = Service(executable_path=path)
# Use ChromeOptions for additional configurations
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
# Initialize the WebDriver with the specified service and options
driver = webdriver.Chrome(service=service, options=options)
# Navigate to the specified website
driver.get(website)
all_matches_button = driver.find_element("xpath", '//label[@analytics-event="All matches"]')
all_matches_button.click()
matches = driver.find_elements(By.TAG_NAME, "tr")
date = []
home_team = []
score = []
away_team = []
for match in matches:
date.append(match.find_element("xpath", "./td[1]").text)
home_team.append(match.find_element("xpath", "./td[2]").text)
home = match.find_element("xpath","./td[2]").text
print(home)
score.append(match.find_element("xpath", "./td[3]").text)
away_team.append(match.find_element("xpath", "./td[4]").text)
# Close the WebDriver when you're done
# driver.quit()
content_copyCOPY
Comments