-
Notifications
You must be signed in to change notification settings - Fork 0
/
columbia.py
87 lines (79 loc) · 4.09 KB
/
columbia.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
85
86
87
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('columbia.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/chromedriver')
time.sleep(0.3)
pagedata=[]
start_url = 'https://www.health.gov.bc.ca/assisted/locator/index.php/displaycommunity/index'
driver.get(start_url)
time.sleep(5)
virtualCommunityOptions = driver.find_elements_by_xpath("//select[@id='search-by-community']/option")
temp = -1
for communityOption in virtualCommunityOptions:
temp += 1
communityOptions = driver.find_elements_by_xpath("//select[@id='search-by-community']/option")
if (communityOptions[temp].text == "Abbotsford") or (communityOptions[temp].text == "Burnaby") or (communityOptions[temp].text == "Vancouver"):
community = communityOptions[temp].text
communityOptions[temp].click()
time.sleep(2)
driver.find_elements_by_css_selector('button#start-alr-search')[0].click()
time.sleep(2)
cards = driver.find_elements_by_css_selector('div.tile')
for card in cards:
nameOfTheResidence = card.find_elements_by_css_selector('div>h3')[0].text
pTags = card.find_elements_by_css_selector('div>p')
for pTag in pTags:
pTagElements = pTag.text.split("\n")
for i in range(len(pTagElements)):
if "Total Assisted Living units:" in pTagElements[i]:
totalAssistedLivingUnits = pTagElements[i].split("Total Assisted Living units:")
if "Publicly subsidized units:" in pTagElements[i]:
publiclySubsidizedUnits = pTagElements[i].split("Publicly subsidized units:")
if "Private pay units:" in pTagElements[i]:
privatePayUnits = pTagElements[i].split("Private pay units:")
if "Address:" in pTagElements[i]:
address = pTagElements[i].split("Address:")
if "Phone:" in pTagElements[i]:
phone = pTagElements[i].split("Phone:")
if "Fax:" in pTagElements[i]:
fax = pTagElements[i].split("Fax:")
if "Website:" in pTagElements[i]:
website = pTagElements[i].split("Website:")
if "Health Authority:" in pTagElements[i]:
healthAuthority = pTagElements[i].split("Health Authority:")
matchDetail = {
'Community': community,
'Name of the residence': nameOfTheResidence,
'Total Assisted Living units': totalAssistedLivingUnits[1],
'Publicly subsidized units': publiclySubsidizedUnits[1],
'Private pay units': privatePayUnits[1],
'Address': address[1],
'Phone': phone[1],
'Fax': fax[1],
'Website': website[1],
'healthAuthority': healthAuthority[1],
}
pagedata.append(matchDetail)
time.sleep(1)
write_csv(pagedata)
print("done")
driver.quit()