Skip to content

Commit

Permalink
fix : Correct data processing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mookseong committed Feb 18, 2023
1 parent e9b9da1 commit 98bb635
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/main/java/org/spoon/lib/category/BaseParserCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.Objects;

public abstract class BaseParserCategory {
protected final String bookQuery = "ul > li > a";
protected BookCategoryType documentType;
protected Document document;

Expand All @@ -31,13 +30,13 @@ public BaseParserCategory(String url, BookCategoryType model) {

public List<BookCategory> getBookList() {
Elements element = extractBookDocument().getElementsByClass(this.documentType.getClassType());
Elements elements = Objects.requireNonNull(element).select(this.bookQuery);
Elements elements = Objects.requireNonNull(element).select(this.documentType.getBookType());
return toArrayList(elements);
}

public List<BookCategory> getBookList(Element element) {
Elements tmpElement = element.getElementsByClass(this.documentType.getClassType());
Elements elements = Objects.requireNonNull(tmpElement).select(this.bookQuery);
Elements elements = Objects.requireNonNull(tmpElement).select(this.documentType.getBookType());
return toArrayList(elements);
}

Expand Down
17 changes: 9 additions & 8 deletions src/main/java/org/spoon/lib/model/BookCategoryType.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package org.spoon.lib.model;

public enum BookCategoryType {
BEST_BOOK("book-best", "col-md-9 sponge-main-book book"),
NEW_BOOK("book-new", "col-md-9 sponge-main-book book"),
EBOOK_BOOK("book-ebook", "col-md-9 sponge-main-book book"),
RECOMMEND_BOOK("book-recommend", "col-md-9 sponge-main-book book"),
RECENT_RENT_BOOK("user-welcome-page-thumb", "col-md-6 bostbooklist");

BEST_BOOK("#book-best > div:nth-child(2) > div > ul > li > a", "col-md-9 sponge-main-book book"),
NEW_BOOK("#book-new > div:nth-child(2) > div > ul > li > a", "col-md-9 sponge-main-book book"),
EBOOK_BOOK("#book-ebook > div:nth-child(2) > div > ul > li > a", "col-md-9 sponge-main-book book"),
RECOMMEND_BOOK("#book-recommend > div:nth-child(2) > div > ul > li > a", "col-md-9 sponge-main-book book"),
RECENT_RENT_BOOK("ul > li > a", "col-md-6 bostbooklist");

private final String bookType;

private final String bookQuery;
private final String classType;

BookCategoryType(String bookType, String classType) {
this.bookType = bookType;
this.bookQuery = bookType;
this.classType = classType;
}

public String getBookType() {
return bookType;
return bookQuery;
}

public String getClassType() {
Expand Down
64 changes: 64 additions & 0 deletions src/test/java/org/spoon/SpoonCategoryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.spoon;

import org.junit.jupiter.api.Test;
import org.spoon.lib.category.ParserBestBookCategory;
import org.spoon.lib.category.ParserEBookCategory;
import org.spoon.lib.category.ParserNewBookCategory;
import org.spoon.lib.category.ParserRentBookCategory;
import org.spoon.lib.model.BookCategory;

import java.util.List;

public class SpoonCategoryTest {
@Test
void getNewBookParser() {
Spoon spoon = new Spoon();
List<BookCategory> parser = spoon.getBookCategory(new ParserNewBookCategory());
System.out.println(" ");
System.out.println("bookNewBook");
for (BookCategory bookList : parser) {
inputCategoryBook(bookList);
}
}

@Test
void getBestBookParser() {
Spoon spoon = new Spoon();
List<BookCategory> parser = spoon.getBookCategory(new ParserBestBookCategory());
System.out.println(" ");
System.out.println("bookBestBook");
for (BookCategory bookList : parser) {
inputCategoryBook(bookList);
}
}


@Test
void getEBookParser() {
Spoon spoon = new Spoon();
List<BookCategory> parser = spoon.getBookCategory(new ParserEBookCategory());
System.out.println(" ");
System.out.println("bookEBook");
for (BookCategory bookList : parser) {
inputCategoryBook(bookList);
}
}

@Test
void getRentBookParser() {
Spoon spoon = new Spoon();
List<BookCategory> parser = spoon.getBookCategory(new ParserRentBookCategory());
System.out.println(" ");
System.out.println("bookRentBook");
for (BookCategory bookList : parser) {
inputCategoryBook(bookList);
}
}

private void inputCategoryBook(BookCategory bookList){
System.out.println("책 제목 : " + bookList.getTitle());
System.out.println("책 사진 : " + bookList.getImage());
System.out.println("책 url : " + bookList.getUrl());
System.out.println("-----------------------------------");
}
}

0 comments on commit 98bb635

Please sign in to comment.