-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_ptit.py
58 lines (39 loc) · 1.97 KB
/
code_ptit.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
from chrome_module import *
class CodePTIT:
def select_language(self, driver: ChromiumPage, language):
language_code = {
'java': '788',
'python': '779'
}
driver.get('https://code.ptit.edu.vn/student/question?course='+ language_code[language])
driver.get('https://code.ptit.edu.vn/student/question')
def get_num_of_page(self, driver: ChromiumPage):
if 'student/question?page=1' not in driver.url:
driver.get('https://code.ptit.edu.vn/student/question?page=1')
page_items = driver.eles('xpath://li[@class="page-item"]')
return len(page_items)
def get_unsolved_tasks(self, page_num, driver: ChromiumPage):
ques_data = []
for i in range(page_num):
driver.get('https://code.ptit.edu.vn/student/question?page=' + str(i + 1))
question_table = driver.ele('xpath://table[@class="ques__table"]/tbody')
unsolv_ques = question_table.eles('xpath:.//tr[not(contains(@class, "bg--10th"))]')
for ques in unsolv_ques:
ques_id = ques.ele('xpath:.//td[3]').text
ques_title = ques.ele('xpath:.//td[4]').text
ques_url = ques.ele('xpath:.//td[3]/a').attr('href')
ques_data.append({'id': ques_id, 'title': ques_title, 'url': ques_url})
return ques_data
def upload_file(self, driver: ChromiumPage, task_url, file_path):
driver.get(task_url)
driver.ele('xpath://input[@id="fileInput"]').input(file_path)
submit_btn = driver.ele('xpath://button[@type="submit"]')
sleep(1)
submit_btn.click(by_js = True)
sleep(2)
if __name__ == '__main__':
driver = getDriver()
driver.get('https://code.ptit.edu.vn')
input('continue once finished logging in')
code_ptit = CodePTIT()
print(code_ptit.get_unsolved_tasks(code_ptit.get_num_of_page(driver), driver))