简体   繁体   中英

JSOUP Title of a link extraction?

im using Java and Jsoup and the portion of HTML I'm trying to utilize is

<i class="fa fa-star"></i> <a href="#taskruns" data-toggle="tab">396900 runs submitted</a>

I just need to extract the title "396900 runs"

How would I go about doing this? I'm fairly new to parsing and web scraping

This is how can you exact text from html.

import java.io.IOException;  
import org.jsoup.Jsoup;  
import org.jsoup.nodes.Document;  
import org.jsoup.nodes.Element;

public class WebScraping{  
    public static void main( String[] args ) throws IOException{  
            String html = "<i class='fa fa-star'></i> <a href='#taskruns' data-toggle='tab'>396900 runs submitted</a>";


            Document doc = Jsoup.parse(html); //First you have to parse html 
            Element link = doc.select("a").first(); //Then find the css selector from which you want to extract data

            String linkText = link.text(); //Then extract the text from selector

            System.out.println(linkText);
    }  
}  

You can learn more from here .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM