-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrap_nu.py
44 lines (35 loc) · 1.23 KB
/
scrap_nu.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
import requests
from bs4 import BeautifulSoup as bs
url = 'http://nu.ac.bd/results/cse/cse_result.php?roll_number=®_no={}&exm_code={}&exam_year={}'
def grab(reg, xm_code, year):
req = requests.get(url.format(reg, xm_code, year))
html = bs(req.text, 'html.parser')
info = html.findAll(attrs={'id':'customers'})
if info:
std_info = _studentINFO(info[0])
std_res = _studentRES(info[1])
std_info['result'] = std_res
return std_info
return {'result': None}
def _studentINFO(info):
td = info.findAll(name='td')
data = {}
for i, t in enumerate(td):
if i%2 != 0:
data[td[i-1].text.strip()] = t.text.strip()
return data
def _studentRES(res):
td = res.findAll(name='td')[5:]
data = {}
for i, dt in enumerate(td):
if i%4 == 3:
if len(str(int(td[i-3].text.strip()))) > 4:
courese_code = '_'+str(int(td[i-3].text.strip()))
else:
courese_code = 'CSE_'+str(int(td[i-3].text.strip()))
data[courese_code] = {
"name": td[i-2].text.strip(),
"cradit": td[i-1].text.strip(),
"grade": dt.text.strip(),
}
return data