[Python] Selenium find_elements not finding all elements

Discussão em 'Python' iniciado por Stack, Maio 11, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to extract data from this website - https://receptes.tvnet.lv/receptes. For most of the links it works well but in few cases it doesn't give me anything. For example, I ran through 100 pages (1800 links in total) and only for 4 I have issue.

    This is part of my code:

    for receptes_link in range(len(productlinks)):
    driver.get(productlinks[receptes_link])
    sastavdala = driver.find_elements(By.XPATH,'//div[@class="container-ingredient_group"]')
    nosaukums = driver.find_elements(By.XPATH, '//h1[@class="header--title"]')
    pagatavosana = driver.find_elements(By.XPATH, '//div[@class="step__container"]')
    kategorija = driver.find_elements(By.XPATH,'//span[@class="breadcrumb--title"]')
    laiks = driver.find_elements(By.XPATH, '//span[@class="preparation_time__text"]')

    print(sastavdala)


    In those 4 cases sastavdala = driver.find_elements(By.XPATH,'//div[@class="container-ingredient_group"]') is returned as empty (for example, https://receptes.tvnet.lv/recepte/23715-latvijas-karoga-kuka) but this tag is clearly there. When extracting page 16 then I can see that 'sastavdala' is blank for this 1 case (~see attachment). All other data is extracting normally in this case but issue is only with sastavdala (~see attachment).

    I tried to put sleep but it didn't help.

    Continue reading...

Compartilhe esta Página