[英]JSOUP Title of a link extraction?
im using Java and Jsoup and the portion of HTML I'm trying to utilize is 我正在使用Java和Jsoup,而我尝试利用的HTML部分是
<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" 我只需要提取标题“ 396900次运行”
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. 这是您如何从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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.