我正在尝试抓取此网页:http://www.bbc.com/earth/columns/record-breakers . 当我尝试获取所有可用链接时,我的程序只返回实际链接的一部分。
如图所示,href 属性值仅包含实际链接的一部分。在网站上,当我将鼠标移到文章上时,它会在屏幕的左下角出现一些带有右侧链接的小框。
我对 HTML 了解不多,但我刚刚了解到它被称为“alt”属性,所以我的问题是如何使用 Jsoup 将此信息显示在左下角?
最佳答案
使用 abs: 属性前缀从属性解析绝对 URL。上面页面的示例:
public static void main (String []args) throws IOException {
Document doc = Jsoup.connect("http://www.bbc.com/earth/columns/record-breakers").get();
Elements link = doc.select("div.promo-unit-header a");
for(Element e : link){
System.out.println(e.attr("abs:href"));
}
}
关于Java Jsoup 提取 "alt",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37020824/