简体   繁体   English

如何使用jsoup提取图像URL

[英]How to extract image urls using jsoup

I want to fetch content from a website, such as title and src attributes of the images. 我想从网站获取内容,例如图像的titlesrc属性。 Can any one help me out to achieve this. 任何人都可以帮助我实现这一目标。

Here is an example of reading all image src and title attributes: 这是读取所有图像srctitle属性的示例:

public class Test {

    public static void main(String[] args) {
        try {
            Document doc = Jsoup.connect("http://www.golem.de/").get();
            Elements imageElements = doc.getElementsByTag("img");
            for (Element element : imageElements) {
                System.out.println("src: "+element.attr("src"));
                System.out.println("title: "+element.attr("title"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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