-
Notifications
You must be signed in to change notification settings - Fork 0
/
alberta.py
86 lines (66 loc) · 2.68 KB
/
alberta.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import csv
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from itertools import islice
def write_csv(pagedata):
res_list = []
for i in range(len(pagedata)):
if pagedata[i] not in pagedata[i + 1:]:
res_list.append(pagedata[i])
pagedata=res_list
with open('alberta.csv', 'w',encoding='ISO-8859-1', newline='') as csvFile:
fields = pagedata[0].keys()
writer = csv.DictWriter(csvFile, fieldnames=fields)
writer.writeheader()
for data in pagedata:
writer.writerow(data)
csvFile.close()
if __name__ == "__main__":
options=webdriver.ChromeOptions()
options.add_argument('start-maximized')
driver = webdriver.Chrome(chrome_options=options,executable_path='/Users/KevinHo/Desktop/jubo/files/chromedriver')
time.sleep(0.3)
pagedata=[]
start_url = 'https://www.albertahealthservices.ca/cc/page15328.aspx#ccfd'
driver.get(start_url)
time.sleep(5)
virtualCareOptions = driver.find_elements_by_xpath("//select[@name='ddlCity'][@id='ddlCity']/option")
temp = -1
for option in virtualCareOptions:
temp += 1
careOptions = driver.find_elements_by_xpath("//select[@name='ddlCity'][@id='ddlCity']/option")
if (careOptions[temp].text == "Banff"):
Care = careOptions[temp].text
print(Care)
careOptions[temp].click()
time.sleep(2)
driver.find_elements_by_css_selector('a#lbtSearch')[0].click()
time.sleep(5)
links = driver.find_elements_by_css_selector('div.gridContainer>a')
linkTemp = -1
for link in links:
linkTemp += 1
realLinks = driver.find_elements_by_css_selector('div.gridContainer>a')
realLinks[linkTemp].click()
time.sleep(1)
operatorName=''
operatorType=''
yearOfBuild=''
Website=''
Address=''
Telephone=''
Fax=''
typeofSite=''
publiclyFundSpaces=''
residentFamilySurveyResults=''
accreditationStatus=''
accreidtationOrganization=''
thTags = driver.find_elements_by_css_selector('table>tbody>tr>th')
thTemp = -1
for thTag in thTags:
thTemp += 1
thTagText = thTag.text
if thTagText == "Type of Site":
typeofSite = thTags[thTemp+1].text