Last active
July 24, 2023 22:14
-
-
Save minhqnd/f5f49dd33573ebde1777ddc03b4b3837 to your computer and use it in GitHub Desktop.
Crawl điểm thi trang https://quangninh.tsdc.edu.vn/tra-cuu-diem-thi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import time | |
# Disable SSL warnings | |
requests.packages.urllib3.disable_warnings() | |
url = "https://quangninh.tsdc.edu.vn/forward-api" | |
headers = { | |
'Content-Type': 'application/json;charset=utf-8', | |
} | |
total_students = 600 # Tổng số thí sinh | |
results = [] | |
for i in range(1, total_students + 1): | |
payload = { | |
"path": "/exammansvc/kythi-controller/tra-cuu-diem-thi", | |
"method": "GET", | |
"data": { | |
"dotTuyenSinhId": "22_DTS_20230428_2673", | |
"sbd": str(330000 + i), # Tăng số báo danh lên 1 | |
"maKyThi": "22_KT_20230430_560" | |
} | |
} | |
try: | |
response = requests.post(url, headers=headers, data=json.dumps(payload), verify=False) | |
data = json.loads(response.text) | |
sbd = data['item'].get('sbd') | |
diemThi = data['item'].get('diemThi') | |
totalPoint = data['item'].get('totalPoint') | |
results_data = data['item'].get('results', []) | |
result_dict = {} | |
if results_data is not None: | |
for result in results_data: | |
ten_bai_thi = result['ten_bai_thi'] | |
diem_thi = result['diem_thi'] | |
ten_bai_thi = ten_bai_thi | |
result_dict[ten_bai_thi] = diem_thi | |
nguyen_vong_results = { | |
"Số báo danh": sbd, | |
"diemThi": diemThi, | |
"totalPoint": totalPoint | |
} | |
nguyen_vong_results.update(result_dict) | |
results.append(nguyen_vong_results) | |
print(f"Đã xong {i}/{total_students} | {nguyen_vong_results}") | |
except requests.exceptions.ConnectionError as e: | |
print(f"Lỗi kết nối: {e}") | |
print("Đợi 10 giây trước khi tiếp tục...") | |
time.sleep(10) | |
continue | |
except Exception as e: | |
print(f"Lỗi không xác định: {e}") | |
continue | |
# Ghi kết quả vào file JSON | |
with open('ket_qua.json', 'w', encoding='utf-8') as file: | |
json.dump(results, file, ensure_ascii=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment