1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Selenium Python: Click all provinces on map and scrape data from opened div

Discussão em 'Python' iniciado por Stack, Agosto 19, 2025.

  1. Stack

    Stack Membro Participativo

    I am using Python and Selenium to scrape data from a website. The page contains an interactive map of provinces.

    url = https://www.dsp.org.tr/yonetim/il-baskanlari

    When I click a province on the map, a new section appears below in a <div class="issues..">. Inside this section, there is a table with information such as: Mayor/Chairman name, Address, Phone number

    Example snippet:

    There is a

    <div class = "svg-turkiye-haritasi">
    <svg version.... > <g id = "turkiye">
    <g id="adana" data-plakakodu="01" data-alankodu="322" data-iladi="Adana" class="active-city">


    My goal is: Click the first province(Adana) on the map. Extract the details from the opened <div>

    <div class="info-content">
    <p class="mayor-tr">
    <strong>İl Başkanı:</strong>
    <span class="info-mayor">AAA</span></p>
    <p class="address-tr d-none">
    <strong>Adres:</strong>
    <span class="info-address">
    <a class="underline-link" href="https..." target="_blank">BBBB</a></span></p>
    <p class="phone-tr d-none">
    <strong>Telefon:</strong>
    <span class="info-phone"><a href="xxxx" class="underline-link">CCCC</a></span</p>
    </div>


    Move to the next province and repeat until all are processed. The problem is that I can’t figure out the best way to: Loop through all clickable provinces on the map, Ensure the <div> content is updated and extract the correct values before moving to the next province.

    in my code, I can find the city :

    driver.execute_script("""
    arguments[0].scrollIntoView({ behavior: 'smooth', block: 'center' });
    arguments[0].style.stroke = 'red';
    arguments[0].style.strokeWidth = '3px';
    arguments[0].style.fillOpacity = '0.5';
    """, province)


    however, i can not click:

    driver.execute_script(
    "arguments[0].dispatchEvent(new MouseEvent('click', {bubbles:true}))",
    province
    )

    Continue reading...

Compartilhe esta Página