I'm doing some web scraping from this website: https://www.adamchoi.co.uk/teamgoals/detailed But when I try to get my .csv file, I get an empty DataFrame. So I decided to test the for loop and print. When I run it I don't get anything in return. I don't understand what is failing
here is my code:
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import pandas as pd
import time
website = 'https://www.adamchoi.co.uk/teamgoals/detailed'
path = r'C:/Users/Ronald C/Downloads/Data Analyst Portfolio Porjects/Project 5 Web Scrapping/chromedriver.exe'
driver = webdriver.Chrome(path)
driver.get(website)
all_matches_button = driver.find_element_by_xpath('//label[@analytics-event="All matches"]')
all_matches_button.click()
drop_country = Select(driver.find_element_by_id('country'))
drop_country.select_by_visible_text('Spain')
time.sleep(5)
drop_season = Select(driver.find_element_by_id('season'))
drop_season.select_by_visible_text('21/22')
# Creating a list with all the matches
matches = driver.find_elements_by_tag_name('tr')
# Extraction of the list "matches"
# match_list = []
# for match in matches:
# match_list.append(match.text)
# driver.quit()
for match in matches:
print(match.text)
CodePudding user response:
@Ramon Cordova, you need to move the statement to wait, after you are selecting "Season" option. In the current case, since it takes a few seconds for the table to populate, you get nothing as the output of for loop.
drop_season = Select(driver.find_element_by_id('season'))
drop_season.select_by_visible_text('21/22')
time.sleep(5)