I have a problem that I do not know how to solve. While fetching data I get NPE. It is weird, because for other categories of book it works normally.
String romancesCategoryEmpikURL = "https://www.empik.com/ksiazki/poradniki";
Document document = Jsoup.connect(romancesCategoryEmpikURL).get();
List<Element> siteElements = document.select("div.productBox__info");
List<Book> romanceCategoryBooks = new ArrayList<>();
for (int i = 0; i < 15; i++) {
String author = siteElements.get(i).select("span > a").first().ownText();
romanceCategoryBooks.add(new Book.BookBuilder()
.withAuthor(author)
.withPrice(price)
.withTitle(title)
.withProductID(productID)
.withBookURL(BookURL)
.build());
}
NPE occurs with fetching author from site: https://www.empik.com/ksiazki/poradniki
HTML code:
<div class="productBox__info">
<a href="/jak-uratowac-swiat-czyli-co-dobrego-mozesz-zrobic-dla-planety-szpura-areta,p1223701396,ksiazka-p" class="productBox seoTitle" title="Jak uratować świat? Czyli co dobrego możesz zrobić dla planety - Szpura Areta" data-product-id="p1223701396">
<span class="productBox__title">
<span class="productBox__number">1</span>
Jak uratować świat? Czyli co dobrego możesz zrobić dla planety
</span>
</a>
<span class="productBox__subtitle">
<a href="/szukaj/produkt?author=szpura+areta" class="smartAuthor" title="Szpura Areta - wszystkie produkty">
Szpura Areta </a>
</span>
<div class="rating">
<ul class="ratingStars"><li class="rate"><i class="fa fa-fw fa-star active"></i></li><li class="rate"><i class="fa fa-fw fa-star active"></i></li><li class="rate"><i class="fa fa-fw fa-star active"></i></li><li class="rate"><i class="fa fa-fw fa-star active"></i></li><li class="rate"><i class="fa fa-fw fa-star active"></i></li></ul>
<div class="score">
4.7/5
</div>
</div>
<div class="productBox__price">
<div class="productBox__priceItem productBox__priceItem--promotion ta-productlist-price ">
37,49 zł </div>
<div class="productBox__priceItem productBox__priceItem--old ta-productlist-oldprice">
49,99 zł </div>
</div>
</div>
I want to fetch author which is Szpura Areta.