-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPandaRetriever.java
More file actions
71 lines (63 loc) · 2.23 KB
/
PandaRetriever.java
File metadata and controls
71 lines (63 loc) · 2.23 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
import java.io.IOException;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import org.jsoup.*;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class PandaRetriever {
public static String mainURL;
private Document homePage;
private Element popularMangaSection;
public PandaRetriever() throws IOException{
mainURL = "http://mangapanda.com";
homePage = Jsoup.connect(mainURL).get();
popularMangaSection = homePage.getElementById("popularlist");
}
public ObservableList<String> getPopMangaNames(){
ObservableList<String> names = FXCollections.observableArrayList();
for(Element x : popularMangaSection.getElementsByClass("popularitemcaption")){
names.add(new String(x.ownText()));
}
return names;
}
public void generateChaptersPage(String mangaName){
Element chosenElement = popularMangaSection.select("a:contains(" + mangaName + ")").get(0);
//System.out.println(mainURL + chosenElement.attr("href"));
Document chapterPage = null;
ObservableList<String> chapts = FXCollections.observableArrayList();
try {
//Connect to the URL of the page with the chosen manga's chapters
chapterPage = Jsoup.connect(mainURL + chosenElement.attr("href")).get();
} catch (IOException e) {
e.printStackTrace();
}
Elements chapterElements = chapterPage.select("tr td:has(div.chico_manga)");
for(Element x : chapterElements){
chapts.add(x.text());
}
Stage stage = new Stage();
stage.setTitle(mangaName);
BorderPane tempRoot = new BorderPane();
Scene scene = new Scene(tempRoot, 500, 500);
stage.setScene(scene);
stage.show();
ListView lv = new ListView(chapts);
lv.setOnMouseClicked(new EventHandler<MouseEvent>(){
public void handle(MouseEvent e) {
try {
stage.close();
new MangaChapterView(mainURL + chapterElements.get(lv.getSelectionModel().getSelectedIndex()).getElementsByTag("a").attr("href"));
} catch (IOException e1) {
e1.printStackTrace();
}
}});
tempRoot.setCenter(lv);
}
}