如何从描述标签中的“src =”获取图像的 url
例子:
< description><div class="rss_thumbnail"><img src="image url".......
使用 Jsoup 库
我的代码:
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);}
最佳答案
根据 HTML,您可以尝试使用以下方法获取链接
elements.get(i).select("img").first().attr("src")
或者
elements.get(i).select("a").first().attr("href")
您可能需要试用一段时间。有时 Jsoup 不能很好地与链接配合,无论出于何种原因。
关于java - 使用jsoup获取图片url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28996995/