-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGameUrlScraper.java
More file actions
64 lines (54 loc) · 1.55 KB
/
GameUrlScraper.java
File metadata and controls
64 lines (54 loc) · 1.55 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
import java.util.ArrayList;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public class GameUrlScraper {
private ArrayList<String> gameIds;
public GameUrlScraper() {
gameIds = new ArrayList<String>();
String seasonBase = "http://www.j-archive.com/showseason.php?season=";
//get all game links for each season
for (int i = 1; i < 31; i++) {
String seasonLink = seasonBase + i;
getGameLinks(seasonLink);
}
}
public ArrayList<String> getGameIds() {
return gameIds;
}
private void getGameLinks(String seasonLink) {
URL url;
String html = "";
BufferedReader incomingHTML;
try {
url = new URL(seasonLink);
try {
incomingHTML = new BufferedReader(new InputStreamReader(url.openStream()));
String currLine;
currLine = incomingHTML.readLine();
StringBuilder str = new StringBuilder();
while (currLine != null) {
str.append(currLine);
currLine = incomingHTML.readLine();
}
incomingHTML.close();
html = str.toString();
}
catch (IOException e) {
e.printStackTrace();
}
}
catch (MalformedURLException e) {
e.printStackTrace();
}
Pattern p = Pattern.compile("<a href=\".*?game_id=([0-9]+)\">");
Matcher m = p.matcher(html);
while (m.find()) {
gameIds.add(m.group(1));
}
}
}