-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhtml.java
More file actions
243 lines (197 loc) · 6.98 KB
/
html.java
File metadata and controls
243 lines (197 loc) · 6.98 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import java.io.*;
import java.net.*;
public class html{
static int classNum = 10000; //last found class
public static void main(String [] args) throws IOException
{
//classNum = 10000;
int cnt = 0;
PrintWriter writer = new PrintWriter("CoursesFall2017.txt", "UTF-8"); //instanciate print writer
while(classNum != 40000) //gets 1000 classes from the website
{
/* if(classNum == 11003 || classNum == 11004)
classNum++;
else
{ */
String url = getUrlSource("http://www.courses.as.pitt.edu/detail.asp?CLASSNUM="+classNum+"&TERM=2181");
if(!url.equals("")) //make sure the webspage actually exsists
{
//System.out.println("Class # - " + classNum);
//System.out.println(url);
//write to text file here
writer.println(classNum); //writes class number to file
writer.println(url); //writes all other info to file
cnt++;
//System.out.println(classNum + " - " + cnt);
}
classNum++;
}
writer.close(); //close the file here
/* catch(Exception e){
System.out.println("ERROR! Exiting Program!" + e);
System.exit(0);
} */
}
private static String getUrlSource(String url) throws IOException {
URL yahoo = new URL(url);
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream(), "UTF-8"));
String inputLine;
StringBuilder a = new StringBuilder();
StringBuilder temp = new StringBuilder();
while ((inputLine = in.readLine()) != null)
{
if(inputLine.contains("<td>2181</td>")) //to find place where we need to start parsing,
{ //Always change the term number to current term when updating
temp.append(inputLine+"\n");
temp.delete(0,8);
temp.delete(4,9);
a.append(temp.toString());
temp.setLength(0);
//System.out.println("In Loop\n");
int itemCount = 0;
while(itemCount < 5)
{
//THIS SCRAPS THE TERM, SUBJECT, CATALOG #, TITLE(CLASS NAME), CREDITS, GEN EDS. MET
temp.append(in.readLine());
temp.delete(0,8);
if(itemCount < 2)
{
int start = temp.indexOf("<");
int end = temp.indexOf(">");
temp.delete(start,end+1);
}
else if(itemCount == 2)//in other words if its the course name / title
{
temp.delete(0,12);
int start = temp.indexOf("<");
int end = temp.indexOf(">");
temp.delete(start,end+1);
}
else if(itemCount == 3) //credits
{
int start = temp.indexOf("<");
int end = temp.indexOf(">");
temp.delete(start,end+1);
}
else //gen ed requirements that this class meets
{
temp.delete(0,9);
while(temp.indexOf("&") != -1)
{
int _and = temp.indexOf("&");
int _semicolon = temp.indexOf(";");
temp.delete(_and, _semicolon+1);
temp.append("\t");
}
int start = temp.indexOf("<");
int end = temp.indexOf(">");
temp.delete(start,end+1);
}
//temp.delete(temp.lastIndexOf(temp.toString())-5,temp.lastIndexOf(temp.toString()));
//inputLine.delete(0,3);
a.append(temp.toString() + "\n");
temp.setLength(0);
itemCount++;
}
}
else if(inputLine.contains(">Description<")) //GET DESCRIPTION!!
{
temp.append(inputLine+"\n");
temp.delete(0,39);
while(temp.indexOf("<") != -1)
{
int start = temp.indexOf("<");
int end = temp.indexOf(">");
temp.delete(start,end+1);
}
//move to description -- deleting <> characters until description is reached
int x = 0;
while(x < 3)
{
temp.append(in.readLine());
int start = temp.indexOf("<");
int end = temp.indexOf(">");
temp.delete(start,end+1);
x++;
}
temp.append(in.readLine()); //this is the description
a.append(temp.toString() + "\n");
temp.setLength(0);
}
else if(inputLine.contains(">Prerequisite")) //GET Prerequisite(s)
{
temp.append(inputLine+"\n");
temp.delete(0,55);
temp.append(in.readLine());
temp.append(in.readLine());
temp.append(in.readLine());
temp.append(in.readLine()); //prereq.
if(temp.indexOf("&") != -1)
{
int _and = temp.indexOf("&");
int y = temp.indexOf("p;");
temp.delete(_and, y+2);
}
/* //remove table tag yet again!!
while(temp.indexOf("<") != -1)
{
int start = temp.indexOf("<");
int end = temp.indexOf(">");
temp.delete(start,end+1);
} */
a.append(temp.toString() + "\n");
temp.setLength(0);
}
else if(inputLine.contains(Integer.toString(classNum))) //GET to row containing classNum
{
//move to class time/room -- deleting <> characters until reached
temp.append(inputLine);
/* int start = temp.indexOf("<");
int end = temp.indexOf(">");
temp.delete(start,end+1); */
temp.delete(0,13);
temp.append(in.readLine());
temp.append(in.readLine());
/* while(temp.indexOf("<") != -1)
{
int start2 = temp.indexOf("<");
int end2 = temp.indexOf(">");
temp.delete(start2,end2+1);
} */
temp.delete(0,40);
temp.append(in.readLine());
temp.delete(0,20);
temp.append(in.readLine()); //get to class time/room
temp.delete(0,20);
/* int start2 = temp.indexOf("<");
int end2 = temp.indexOf(">");
temp.delete(start2,end2+1); */
/* int _and = temp.indexOf("&");
int semi = temp.indexOf(";");
temp.delete(_and, semi); */
a.append(temp.toString() + "\n");
temp.setLength(0); //PLACE CLASS TIME/ROOM in TEMP
//NOW GET PROFESSOR
for(int i = 0; i<14; i++)
in.readLine();
temp.append(in.readLine());
while(temp.indexOf("<") != -1)
{
int start = temp.indexOf("<");
int end = temp.indexOf(">");
temp.delete(start,end+1);
}
a.append(temp.toString() + "\n");
temp.setLength(0);
}
//CHECK FOR NEW INDICATOR HERE TO GATHER OTHER ITEMS
}
in.close();
return a.toString();
}
}
/*
DETAILS OF HOW TO STORE FILE:
Term : Subject(major) : Catalog # : Title(class name) : ..... in order
*/