-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththanwya.py
193 lines (152 loc) · 7.82 KB
/
thanwya.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
from playwright.sync_api import sync_playwright
from bs4 import BeautifulSoup
import pandas as pd
# import time
logo = """
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
/T\ /h\ /a\ /n\ /a\ /w\ /e\ /y\ /a\ /R\ /e\ /s\ /u\ /l\ /t\ /s\
<___><___><___><___><___><___><___><___><___> <___><___><___><___><___><___><___>
\n
Made by Soliman2020
"""
print(logo)
while True:
try:
start = int(input('Enter a start seating num in range 100000-999999 >>> '))
except ValueError:
print ("That's not a number!")
else:
if 100000 <= start < 999999:
size = int(input('Please enter how many iterations you want to apply >>> '))
last = start + size
print('processing, please wait...')
break
else:
print ('Out of range. Try again')
# > seating numbers MIX
seating_nos = [*range(start,last,1)]
# seating_nos = [*range(870000,870101,1)]
# seating_nos = [865231,868686,868682,481548,893538,387692,173148,234727,546254]
desk_nums = []
percentages = []
# student_names = [] # PLZ Keep hidden for privacy!
school_names = []
directorates = []
citys = []
assessment = []
divisions = []
Arabic_scores = []
F_1_scores = []
F_2_scores = []
pure_mathematics = []
history_scores = []
geography_scores = []
philosophy_scores = []
psychology_scores = []
chemistry_scores = []
biology_scores = []
geology_scores = []
applied_math = []
physics_scores = []
total_scores = []
def core():
Total_Wrong = 0
Total_Right = 0
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
# > the target website
page.goto('https://natega.cairo24.com/', timeout = 0)
for seating_num in seating_nos:
page.is_visible('div.all')
# time.sleep(1)
page.fill('input#seating_no',str(seating_num))
page.click('input#submit')
Ideal = page.is_hidden('center.field-validation-valid:nth-child(3)')
print(Ideal)
if Ideal == True:
Total_Right=Total_Right+1
print(f'#Right_seating_number = {Total_Right} \n#Wrong_seating_number = {Total_Wrong}\n#Total = (( {Total_Wrong+Total_Right} ))\n')
# > permit only valid seating numbers (no page error promot)
if Ideal == False:
Total_Wrong=Total_Wrong+1
print(f'#Right_seating_number = {Total_Right} \n#Wrong_seating_number = {Total_Wrong}\n#Total = (( {Total_Wrong+Total_Right} ))\n')
continue
# > read full html page
html = page.inner_html('html')
# > BeautifulSoup process
soup = BeautifulSoup(html,'html.parser')
# > student status
desk_no = soup.select('li.col:nth-child(1)>h1')[0].text
desk_nums.append(desk_no)
total = soup.select('li.col:nth-child(2)>h1')[0].text
total_scores.append(total)
percentage = soup.select('li.col:nth-child(3)>h1')[0].text
# percentage_value = percentage_loc[0].text
percentages.append(percentage)
school_name = soup.select('.full-result > ul:nth-child(1) > li:nth-child(2) > span:nth-child(2)')[0].text
school_names.append(school_name)
directorate = soup.select('.full-result > ul:nth-child(1) > li:nth-child(3) > span:nth-child(2)')[0].text
directorates.append(directorate)
status = soup.select('.full-result > ul:nth-child(1) > li:nth-child(5) > span:nth-child(2)')[0].text.strip()
assessment.append(status)
division = soup.select('.full-result > ul:nth-child(1) > li:nth-child(7) > span:nth-child(2)')[0].text
divisions.append(division)
page.is_visible('.RightSide2')
arabic = soup.select('div.result-details:nth-child(2) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(1) > span:nth-child(2)')[0].text
Arabic_scores.append(arabic)
foreign_1 = soup.select('div.result-details:nth-child(2) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(2) > span:nth-child(2)')[0].text
F_1_scores.append(foreign_1)
foreign_2 = soup.select('div.result-details:nth-child(2) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(3) > span:nth-child(2)')[0].text
F_2_scores.append(foreign_2)
pm = soup.select('div.result-details:nth-child(2) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(4) > span:nth-child(2)')[0].text
pure_mathematics.append(pm)
history = soup.select('div.result-details:nth-child(2) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(5) > span:nth-child(2)')[0].text
history_scores.append(history)
geo = soup.select('div.result-details:nth-child(2) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(6) > span:nth-child(2)')[0].text
geography_scores.append(geo)
philo = soup.select('div.result-details:nth-child(2) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(7) > span:nth-child(2)')[0].text
philosophy_scores.append(philo)
psych = soup.select('div.result-details:nth-child(2) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(8) > span:nth-child(2)')[0].text
psychology_scores.append(psych)
chemistry = soup.select('div.result-details:nth-child(2) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(9) > span:nth-child(2)')[0].text
chemistry_scores.append(chemistry)
biology = soup.select('div.result-details:nth-child(2) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(10) > span:nth-child(2)')[0].text
biology_scores.append(biology)
geology = soup.select('div.result-details:nth-child(2) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(11) > span:nth-child(2)')[0].text
geology_scores.append(geology)
am = soup.select('div.result-details:nth-child(2) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(12) > span:nth-child(2)')[0].text
applied_math.append(am)
physics = soup.select('div.result-details:nth-child(2) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(13) > span:nth-child(2)')[0].text
physics_scores.append(physics)
# > To retart query for new desk number
page.go_back(timeout=0)
natega_df = pd.DataFrame({'desk_no': desk_nums,
'school_name': school_names,
'directorate': directorates,
'arabic':Arabic_scores,
'first_foreign_lang':F_1_scores,
'second_foreign_lang':F_2_scores,
'pure_mathematics':pure_mathematics,
'history':history_scores,
'geology':geology_scores,
'philosophy':philosophy_scores,
'psychology':psychology_scores,
'chemistry':chemistry_scores,
'biology':biology_scores,
'geography':geography_scores,
'applied_math':applied_math,
'physics':physics_scores,
'division':divisions,
'total_scores':total_scores,
'percentage':percentages,
'status':assessment
})
print('The top rows of your results:\n',natega_df.head())
natega_df.to_csv(f'natega_valid_range_{start}_to_{last-1}.csv',index=False)
print('\nResults are ready, check the output CSV file.\n')
def main():
core()
k=input("Press 'Enter' to close this windows...\n")
if __name__ == '__main__':
main()