Created
May 9, 2020 20:22
-
-
Save aydinemre/60d3742d17bc2a9fbdd01c6a918bc7d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import pandas as pd | |
from selenium import webdriver | |
from selenium.webdriver.support.select import Select | |
driver = webdriver.Chrome(executable_path='./chromedriver') | |
belediyeler = ['basaksehir-belediyesi-arsa-rayic'] | |
columns = ['Mahalle Adı', 'Cadde/Sokak Adı', 'Yıl', 'Rayiç Değeri (TL)'] | |
df = pd.DataFrame(columns=columns) | |
for belediye in belediyeler: | |
driver.get("https://www.turkiye.gov.tr/{}".format(belediye)) | |
mahalleler = [m.text for m in Select(driver.find_element_by_id('mahalle')).options[1:]] | |
yillar = [y.text for y in Select(driver.find_element_by_id('yil')).options] | |
for mahalle, yil in itertools.product(mahalleler, yillar): | |
driver.get("https://www.turkiye.gov.tr/{}".format(belediye)) | |
mahalleler = Select(driver.find_element_by_id('mahalle')) | |
yillar = Select(driver.find_element_by_id('yil')) | |
mahalleler.select_by_visible_text(mahalle) | |
yillar.select_by_visible_text(yil) | |
print("Mahalle : {} Yil : {}".format(mahalle, yil)) | |
driver.find_element_by_name('btn').submit() | |
table = driver.find_elements_by_tag_name('tr') | |
data = [t.get_attribute('textContent').replace('\n', '').strip() for t in table[1:]] | |
data = [[i for i in d.split('\t') if i.strip() != ''] for d in data] | |
df = df.append(pd.DataFrame(data, columns=columns), ignore_index=True) | |
df.to_csv('rayic_bedelleri.csv', index=False) | |
driver.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment