Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Main {
static List<DayItem> dayItemList;
public static void main(String[] args) throws IOException {
Document doc = Jsoup.connect("http://www.zspolice.pl/zspolice/zastepstwa").get();
Elements paragraphs = doc.select("p");
Elements tables = doc.select("table");
dayItemList = new ArrayList<DayItem>();
int i = 0;
for(Element paragraph : paragraphs) {
if(paragraph.toString().contains("r.")) {
DayItem dayItem = new DayItem();
dayItem.setDayName(paragraph.html());
List<ReplacementItem> replacementItemList = new ArrayList<ReplacementItem>();
for(int e = 1; e < tables.get(i).select("tr").size(); e++) {
ReplacementItem replacementItem = new ReplacementItem();
for(int u = 0; u < tables.get(i).select("tr").get(e).select("td").size(); u++) {
if(u == 0) {
replacementItem.setReplacementFor(tables.get(i).select("tr").get(e).select("td").get(u).html());
}else if(u == 1) {
replacementItem.setLesson(tables.get(i).select("tr").get(e).select("td").get(u).html());
}else if(u == 2) {
replacementItem.setClassName(tables.get(i).select("tr").get(e).select("td").get(u).html());
}else if(u == 3) {
replacementItem.setTeacher(tables.get(i).select("tr").get(e).select("td").get(u).html());
}else if(u == 4) {
replacementItem.setCourseType(tables.get(i).select("tr").get(e).select("td").get(u).html());
}
}
replacementItemList.add(replacementItem);
}
dayItem.setReplacementItemList(replacementItemList);
dayItemList.add(dayItem);
i++;
}
}
printTable(dayItemList);
}
private static void printTable(List<DayItem> dayItemList) {
for(DayItem dayItem : dayItemList) {
System.out.println(dayItem.getDayName());
for(ReplacementItem replacementItem : dayItem.getReplacementItemList()) {
System.out.printf("%-30s %-30s %-30s %-30s %-30s %n",
replacementItem.getReplacementFor(), replacementItem.getLesson(), replacementItem.getClassName(), replacementItem.getTeacher(), replacementItem.getCourseType());
}
}
}
public static class DayItem {
private String dayName;
private List<ReplacementItem> replacementItemList;
public DayItem() {
}
public String getDayName() {
return dayName;
}
public void setDayName(String dayName) {
this.dayName = dayName;
}
public List<ReplacementItem> getReplacementItemList() {
return replacementItemList;
}
public void setReplacementItemList(List<ReplacementItem> replacementItemList) {
this.replacementItemList = replacementItemList;
}
}
public static class ReplacementItem {
private String replacementFor;
private String lesson;
private String className;
private String teacher;
private String courseType;
public ReplacementItem() {
}
public String getReplacementFor() {
return replacementFor;
}
public void setReplacementFor(String replacementFor) {
this.replacementFor = replacementFor;
}
public String getLesson() {
return lesson;
}
public void setLesson(String lesson) {
this.lesson = lesson;
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
public String getTeacher() {
return teacher;
}
public void setTeacher(String teacher) {
this.teacher = teacher;
}
public String getCourseType() {
return courseType;
}
public void setCourseType(String courseType) {
this.courseType = courseType;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.