-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtua.py
49 lines (41 loc) · 1.64 KB
/
vtua.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
import requests
found = []
cookies = {
'PHPSESSID': 'cgth29ngpdmq4803mqedpvd933',
}
headers = {
'Origin': 'http://csn.vtua.gov.lv',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 OPR/55.0.2994.44',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Accept': '*/*',
'Referer': 'http://csn.vtua.gov.lv/',
'X-Requested-With': 'XMLHttpRequest',
'Connection': 'keep-alive',
'DNT': '1',
}
# for exam_id in range(324692, 328928):
for exam_id in range(328500, 328928):
data = [
('action', 'questionList'),
('examid', exam_id),
]
response = requests.post('http://csn.vtua.gov.lv/files/exam_questions.php',
headers=headers, cookies=cookies, data=data)
for question in response.json()['exam_questions']:
if question not in found:
found.append(question)
data = [
('action', 'examQuestion'),
('examid', exam_id),
('question_id', question),
('lang', 'lv'),
]
response = requests.post('http://csn.vtua.gov.lv/files/exam_questions.php',
headers=headers, cookies=cookies, data=data)
print("{} {}".format(question, response.json()['text']))
with open('data/{}.json'.format(question), 'wb') as fd:
for chunk in response.iter_content(chunk_size=128):
fd.write(chunk)
print("\n Total: {}".format(len(found)))