要从一个HTML文档要从中提取数据,并了解这个HTML文档的结构需要先将HTML解析成一个Document之后,然后使用类似于DOM的方法进行操作。
File input = new File("/file/input.html");
Document doc = Jsoup.parse(input, "UTF-8", "http://baidu.com/");
Element content = doc.getElementById("content");
Elements links = content.getElementsByTag("a");
for (Element link : links) {
String linkHref = link.attr(