Extract image src using JSoup

后端 未结 3 1708
無奈伤痛
無奈伤痛 2021-01-12 16:50

I am trying to extract all the image url\'s from this webpage using jsoup? Can anyone offer help on how to do it? All the tags are formatted like this, but I only need the s

相关标签:
3条回答
  • 2021-01-12 17:06

    Supposing you already have the Element according to this IMG, try this:

    String source = img.attr("src");

    This attr method is inherited from Node class

    HTH

    0 讨论(0)
  • 2021-01-12 17:08

    You should be able to do something like this to get all img tags:

    for (Element e : doc.select("img")) {
        System.out.println(e.attr("src"));
    }
    

    This should select all img tags and then grab the src attribute and print to the console.

    0 讨论(0)
  • 2021-01-12 17:22
    Document document = Jsoup.connect(" http://www.ncataggies.com/PhotoAlbum.dbml?DB_OEM_ID=24500&PALBID=417884").get();
    
            Elements elements =document.getElementsByTag("IMG");
            for(int i=0;i<elements.size();i++)
            {
                System.out.println("Sources of "+ i +":"+elements.get(i).attr("src"));
            }
    
    0 讨论(0)
提交回复
热议问题