public Book createBook(Element bookElement, Element bookIndexElement) { Book book = new Book(bookElement.text().trim()); Elements chapterUrlElements = bookIndexElement.select("a"); for (Element link : chapterUrlElements) { String chapterPage = link.attr("href"); int chapterID = Integer.parseInt(link.text()); Chapter chapter = createChapter(chapterID, chapterPage); book.addChapter(chapter); } return book; }