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>
You can just get it by the class name:
Element li = doc.select("#toclimit-3 > li").first();
String result = li.select(".toctext").first().text();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.