1

I am having trouble scraping the table of contents on wiki. I am making a simple web scraper for a personal project and I can't figure out how to scrape this data.

Here is my attempt at scraping the table of contents from any given wiki page

 String contentOver = doc.select("#toclimit-3 > li").first().text();

HERE IS THE CODE FROM THE PAGE I want to scrape, how do I get just the word "Chronology"?:

    <ul> 
    <li class="toclevel-1 tocsection-1"><a href="#Chronology"><span class="tocnumber">1</span> <span class="toctext">Chronology</span></a></li>
StreamingBits
  • 137
  • 11

1 Answers1

1

You can just get it by the class name:

 Element li = doc.select("#toclimit-3 > li").first();
 String result = li.select(".toctext").first().text();
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195