-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·75 lines (66 loc) · 2.69 KB
/
main.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
import urllib
import re
from urlhandler import *
from scrapeclasses import *
class subjectpage:
def __init__ (self, url):
self.page = urllib.urlopen(url)
def fromsubjectpage (self):
url2 = "null"
while 1:
pline = self.page.readline()
if not pline:
break
if '<td><a href' in pline:
tempurl = re.sub('<td><a href="', "", pline)
tempurl = re.sub('">.*', "", tempurl).strip()
url = "https://www.star.euclid.ed.ac.uk/ipp/" + tempurl
pline = self.page.readline()
if (("Not" not in pline) and ('italic' not in pline) and (url != url2)):
finder = fromurl(url)
ha = finder.run()
url2 = url
class schoolpage:
def __init__ (self, url):
self.page = urllib.urlopen(url)
def fromschoolpage (self):
while 1:
pline = self.page.readline()
if not pline:
break
if '<a href="cx_sb' in pline:
tempurl = re.sub('<li><a href="', "", pline)
tempurl = re.sub('">.*', "", tempurl).strip()
url = "https://www.star.euclid.ed.ac.uk/ipp/" + tempurl
scrapesubjects = subjectpage(url)
hm = scrapesubjects.fromsubjectpage()
class mainpage:
def __init__ (self, url):
self.page = urllib.urlopen(url)
def frommainpage (self):
schoolnumber = 0
while 1:
pline = self.page.readline()
if not pline:
break
if '<a href="cx_s' in pline:
schoolnumber += 1
print "School ", schoolnumber, " of 23"
tempurl = re.sub('<li><a href="', "", pline)
tempurl = re.sub('">.*', "", tempurl).strip()
url = "https://www.star.euclid.ed.ac.uk/ipp/" + tempurl
scrapeschool = schoolpage(url)
hm = scrapeschool.fromschoolpage()
output = open('output.txt', 'w')
#Main program
program = mainpage("http://www.star.euclid.ed.ac.uk/ipp/cx_schindex.htm")
hm = program.frommainpage()
#To test individual schools
#program = schoolpage("http://www.star.euclid.ed.ac.uk/ipp/cx_s_su780.htm")
#hm = program.fromschoolpage()
#To test individual subject-areas
#scrapesubjects = subjectpage("http://www.star.euclid.ed.ac.uk/ipp/cx_sb_accn.htm")
#hm = scrapesubjects.fromsubjectpage()
#To test individual courses
#program = fromurl("http://www.star.euclid.ed.ac.uk/ipp/cxelee09008.htm")
#running = program.run()