简体   繁体   English

使用jsoup获取图片网址

[英]Get image url using jsoup

How can i get the url of an image from "src =" within description tag 如何从描述标签中的“src =”获取图像的网址

example : 例如:

 < description>&lt;div class="rss_thumbnail"&gt;&lt;img src="image url".......

Using Jsoup library 使用Jsoup库
My code : 我的代码:

  Document doc = Jsoup.connect(link).get();
            elements = doc.select("item");

            for (int i = 0; i < elements.size(); i++) {
                FeedItem mItem = new FeedItem();
                mItem.setImageLink(elements.get(i).select("img").attr("src"));
                mItem.setTitle(elements.get(i).select("title").first().toString());
                mItem.setPubDate(elements.get(i).select("pubDate").first().text());
                mItem.setDescription(elements.get(i).select("description").first().text());
                mItem.setLink(elements.get(i).select("link").first().nextSibling().toString());
                feedItemList.add(mItem);}

Depending on the HTML, you can try to get the link by using 根据HTML,您可以尝试使用获取链接

elements.get(i).select("img").first().attr("src")

Or 要么

elements.get(i).select("a").first().attr("href")

You might have to play around with it for a while. 你可能不得不玩一会儿。 Sometimes Jsoup doesn't cooperate well with links for whatever reason. 无论出于何种原因,Jsoup都不能很好地与链接合作。

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

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