-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDataScrape.py
142 lines (113 loc) · 4.24 KB
/
DataScrape.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import time
import requests
from bs4 import BeautifulSoup
import json
import pandas as pd
from Database import SelectQuery,Query
from tkinter.messagebox import showinfo
def GetProvinces() -> list:
ProvinceList = []
cookies = {
'lifecode': 'jfal4q3a37c7ql6ukf138g1l4r',
}
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
# 'Cookie': 'lifecode=jfal4q3a37c7ql6ukf138g1l4r',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
}
response = requests.get('http://apps.moha.gov.lk:8090/lifecode/village_list',
cookies=cookies, headers=headers, verify=False)
soup = BeautifulSoup(response.content, "html.parser")
provinces = soup.find("select")
for province in provinces:
if (province.getText()[3:] != 'ect a Province'):
try:
ProvinceList.append(
{"name": province.getText()[3:], "value": province["value"]})
except:
pass
else:
pass
return ProvinceList
def GetProvinceDistricts(province: str) -> list:
DistrictList = []
cookies = {
'lifecode': 'jfal4q3a37c7ql6ukf138g1l4r',
}
headers = {
'Accept': '*/*',
'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8',
'Connection': 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
# 'Cookie': 'lifecode=jfal4q3a37c7ql6ukf138g1l4r',
'Origin': 'http://apps.moha.gov.lk:8090',
'Referer': 'http://apps.moha.gov.lk:8090/lifecode/village_list',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest',
}
data = {
'action': 'province',
'query': province["value"],
}
response = requests.post(
'http://apps.moha.gov.lk:8090/lifecode/views/fetch.php',
cookies=cookies,
headers=headers,
data=data,
verify=False,
)
soup = BeautifulSoup(json.loads(response.content)["output"], "html.parser")
districts = soup.find_all("option")
for district in districts:
if (district.getText() != "Select a District"):
try:
DistrictList.append(
{"name": district.getText()[3:], "value": district["value"]})
except:
pass
else:
pass
return DistrictList
def GetDistrictDevisions(district):
DevisonList = []
cookies = {
'lifecode': 'jfal4q3a37c7ql6ukf138g1l4r',
}
headers = {
'Accept': '*/*',
'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8',
'Connection': 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
# 'Cookie': 'lifecode=jfal4q3a37c7ql6ukf138g1l4r',
'Origin': 'http://apps.moha.gov.lk:8090',
'Referer': 'http://apps.moha.gov.lk:8090/lifecode/village_list',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest',
}
data = {
'action': 'district',
'query': district["value"],
}
response = requests.post(
'http://apps.moha.gov.lk:8090/lifecode/views/fetch.php',
cookies=cookies,
headers=headers,
data=data,
verify=False,
)
soup = BeautifulSoup(json.loads(response.content)["output"], "html.parser")
devisions = soup.find_all("option")
for devision in devisions:
if (devision.getText() != "Select a Divisional Secretariat"):
try:
DevisonList.append({"name": devision.getText()[
3:], "value": devision["value"]})
except:
pass
else:
pass
return DevisonList