link 提取的 JSOUP 标题?

JSOUP Title of a link extraction?

我正在使用 Java 和 Jsoup,我尝试使用的 HTML 部分是

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

我只需要提取标题“396900 runs”

我该怎么做?我对解析和网络抓取还很陌生

这就是您如何从 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);
    }  
}  

您可以从 here 中了解更多信息。