[Python] Issue in scraping data

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

  1. Stack

    Stack Membro Participativo

    I have an issue in scraping schools data. I need their email and website URL. I tried a lot but it's returning empty results.

    What's the best way to do this?

    Here is the code:

    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service
    from selenium.webdriver.common.by import By
    from webdriver_manager.chrome import ChromeDriverManager
    from selenium.webdriver.chrome.options import Options
    import time

    def google_search(query, num_results=10):
    options = Options()
    options.add_argument("--headless") # Run headless browser
    options.add_argument("--disable-blink-features=AutomationControlled")
    options.add_argument("--no-sandbox")
    options.add_argument("--disable-dev-shm-usage")

    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)

    search_url = f"https://www.google.com/search?q={query}&num={num_results}"
    driver.get(search_url)

    time.sleep(2)

    links = []
    results = driver.find_elements(By.CSS_SELECTOR, 'div.yuRUbf > a')
    for result in results:
    href = result.get_attribute('href')
    if href:
    links.append(href)

    driver.quit()
    return links


    query = "PSHE site:.sch.uk"
    results = google_search(query, num_results=20)

    for i, url in enumerate(results, 1):
    print(f"{i}. {url}")

    Continue reading...

Compartilhe esta Página