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

Time:10-18

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)

CodePudding user response:

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>
  • Related