Home > other >  Problem with scraping in Selenium. It does not scrape
Problem with scraping in Selenium. It does not scrape

Time:11-24

I would like to get the number of rounds (14, 15, 16, 17, etc.), then just scrape the numbers, no ".ROUND". I wrote a basic version and a better version, but they don't work. I don't get errors, but I get >>>> (without any text). How to do?

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 20)

Values_PremierLeague = []

driver.get("https://www.betexplorer.com/soccer/england/premier-league/fixtures/")

wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "th.h-text-left")))

for PremierLeague in driver.find_elements(By.CLASS_NAME, "th.h-text-left"):
    PremierLeague_text = PremierLeague.text
    Values_PremierLeague.append(tuple([PremierLeague_text]))
    print(PremierLeague_text)
driver.close

or

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import re

wait = WebDriverWait(driver, 20)

Values_PremierLeague = []

driver.get("https://www.betexplorer.com/soccer/england/premier-league/fixtures/")

wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".table-main__datetime")))

for PremierLeague in driver.find_elements(By.XPATH, "//*[@class='h-text-left' and contains(text(),'Round')]"):
    PremierLeague_text = PremierLeague.text
    number = re.findall(r'\d ', s)
    Values_PremierLeague.append(tuple([number]))
    print(number)
driver.close

CodePudding user response:

driver.get("https://www.betexplorer.com/soccer/england/premier-league/fixtures/")

wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".table-main__datetime")))

for PremierLeague in driver.find_elements(By.XPATH, "//*[@class='h-text-left' and contains(text(),'Round')]"):
    PremierLeague_text = PremierLeague.text
    number = re.findall(r'\d ', PremierLeague_text)
    Values_PremierLeague.append(tuple([number]))
    print(number)

Not sure what you meant by numbers also not sure why you want tuples. But you had an issue where you never used PremierLeague_text

Outputs:

['13']
['14']
['15']
['16']
['17']
['18']
['19']
['20']
['21']
['22']
['23']
['24']
['25']
['26']
['27']
['28']
['29']
['30']
['31']
['32']
['33']
['34']
['35']
['36']
['37']
['38']
  • Related