[Python] Why doesn't Selenium find elements?

Discussão em 'Python' iniciado por Stack, Fevereiro 1, 2025.

  1. Stack

    Stack Membro Participativo

    I want to scrape the address of the houses from the website, but the code returns no output, can someone tell me where the problem is from?

    here is my code:

    from selenium import webdriver
    from selenium.webdriver.common.by import By

    url= "https://www.zoopla.co.uk/house-prices/england/?new_homes=include&q=england+&orig_q=united+kingdom&view_type=list&pn=1"
    driver=webdriver.Chrome()
    driver.get(url)
    # Find elements using By.CLASS_NAME
    houses = driver.find_elements(By.CLASS_NAME, "w6xkpv1 w6xkpv4")

    for house in houses:
    # Find address within each house element
    address = house.find_element(By.XPATH, './/*[@id="main-content"]/div[2]/div/div/section/div[1]/div[2]/div[1]/div/div/div/div[1]/a/h2').text
    print(address)

    Continue reading...

Compartilhe esta Página