-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.java
More file actions
45 lines (43 loc) · 1.77 KB
/
Copy pathParser.java
File metadata and controls
45 lines (43 loc) · 1.77 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
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import com.google.gson.Gson;
/**
* Author: Aleksey Alekseenko
* Date: 05.07.13
*/
public class Parser {
public static void main(String[] args) {
Document doc;
try {
doc = Jsoup.connect("http://dota-academy.com/herolist")
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36")
.referrer("http://www.google.com").get();
Elements table = doc.select("div[id=tabs-1]");
for (Element row : table.select("tr")) {
Elements tds = row.select("td");
if (!tds.isEmpty()) {
Element link = row.select("a[href]").first();
String detailsUrl = link.attr("href");
Element img = row.select("img[src]").first();
String iconUrl = img.attr("src");
HeroObject heroObject = new HeroObject(tds, detailsUrl, iconUrl);
StringBuffer sb = new StringBuffer("c:\\java education\\dota\\heroes\\");
Gson gson = new Gson();
String json = gson.toJson(heroObject);
FileWriter writer = new FileWriter(String.valueOf(sb.append(heroObject.getNameOfFile()).append(".json")));
writer.write(json);
writer.close();
System.out.println(json);
System.out.println(tds.text());
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}