-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbetreuung.py
66 lines (52 loc) · 2.13 KB
/
betreuung.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import time
import csv
url = "https://service.salzburg.gv.at/weblist/kinderbetreuung/search"
driver = webdriver.Chrome(executable_path='./chromedriver')
driver.get(url)
search_btn = driver.find_elements_by_id('searchSubmit')[0]
search_btn.click()
time.sleep(3)
select = Select(driver.find_element_by_css_selector(
'select[name=searchTable_length]'))
select.select_by_visible_text('Alle')
time.sleep(3)
a_elements = driver.find_elements_by_xpath('//b/a[@href]')
urls = []
mails = []
names = []
for elem in a_elements:
url = elem.get_attribute("href")
urls.append(url)
for elem in urls:
driver.get(elem)
try:
name = driver.find_element_by_tag_name('h3').get_attribute('innerText')
mail = driver.find_element_by_class_name(
'container-fluid').find_element_by_xpath('//div[position()=5]/div/a[@href]').get_attribute('innerText')
mails.append(mail)
names.append(name)
except NoSuchElementException:
continue
print(mails, names)
# filtered_names = filter(lambda x: x != '', names)
# filtered_titles = filter(lambda x: x != '', titles)
# emails = list(filtered_titles)
# schools = list(filtered_names)
# emails_cleaned = emails[3:]
# schools_shortened = schools[370:len(schools)-11]
# unwanted = {'Bildungsdirektion für Salzburg',
# 'Ländliche Hauswirtschaftsschule Klessheim',
# 'Landwirtschaftliche Fachschule Klessheim',
# 'Musikschulen des Vereins "Musikum" in Salzburg (Hauptanstalt)',
# 'Musikschulen des Vereins "Musikum" in Salzburg; Zweigstelle der Musikschule Seekirchen (503530)',
# 'Musikschulen des Vereins "Musikum" in Salzburg; Zweigstelle der Musikschule St.Johann im Pongau (504510)'}
# schools_cleaned = [ele for ele in schools_shortened if ele not in unwanted]
#
combined_lists = [list(a) for a in zip(names, mails)]
driver.quit()
with open('out/betreuung.csv', 'w', newline='') as file:
mywriter = csv.writer(file, delimiter=',')
mywriter.writerows(combined_lists)