How to get specific div eq() in list through jSoup in Android Studio

Issue

I and building an android app using indeed data. For this, I am using jSoup in android studio.
I want to get the full detail of company through indeed’s company detail page.

but here is lil bit of difficulty am facing that almost all classes start with div. I want to use for loop here but because the main class and inside of its class all starts with div, and also there is no specific class name in main class, which i can mention to select that class.

here is the inspect code (Image).enter image description here

Now I want data of reviews-section, but don’t know how to access that specific section because it don’t have its own class name and eq() doesn’t work here because all the above sections have a div tag inside the section for further data.

I want something attentc way to access every section individually or atleast review-section (7) and salary-section (4)

Solution

You can get elements by specifying the attribute name and its value.

String html = 
     "<div>\r\n"
    + "<div data-tn-section=\"AboutSection-section\" style=\"user-select: auto;\"></div>\r\n"
    + "<div data-tn-section=\"jobs-section-no-location\" style=\"user-select: auto;\"></div>\r\n"
    + "<div data-tn-section=\"salary-section\" style=\"user-select: auto;\"></div>\r\n"
    + "<div data-tn-section= \"benefits-section\" style=\"user-select: auto;\"></div>\r\n"
    + "<div data-tn-section=\"ratings-overview-section\" style=\"user-select: auto;\"></div>\r\n"
    + "<div data-tn-section=\"reviews-section\" style=\"user-select: auto;\"></div>\r\n"
    + "<div data-tn-section=\"qna-section\" style=\"user-select: auto;\"></div>\r\n"
    + "<div data-tn-section=\"interviews-section\" style=\"user-select: auto;\"></div>\r\n"
    + "<div data-tn-section=\"faq-section\" style=\"user-select: auto;\"></div>\r\n"
    + "<div data-tn-section=\"LocationsSection\" style=\"user-select: auto;\"></div>\r\n"
    + "<div data-tn-section=\"topic-section\" style=\"user-select: auto;\"></div>\r\n"
    + "</div>\r\n";
Document doc = Jsoup.parse(html);
Elements es = doc.select("div[data-tn-section=reviews-section]");
System.out.println(es);

output

<div data-tn-section="reviews-section" style="user-select: auto;"></div>

Answered By – user17233545

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published