【发布时间】:2017-08-25 16:16:42
【问题描述】:
我想知道如何从 RSS 和 Atom 提要中提取图像,以便在具有相关标题、描述和链接的容器中显示提要时将它们用作缩略图。到目前为止,我的代码(如下所示)仅从特定类型的提要中抓取图像,我想知道如何抓取脚本遇到的每张图像。
if (feed_image_type == "description") {
item_img = $($(this).find('description').text()).find("img").attr("src");
} else if (feed_image_type == "encoded") {
item_img = $($(this).find('encoded').text()).find("img").attr("src");
} else if (feed_image_type == "thumbnail") {
item_img = $(this).find('thumbnail').attr('url');
} else {
item_img = $(this).find('enclosure').attr('url');
}
例如,我不知道如何从下面的代码 rss 提要 sn-p 中获取图像链接:
<description>
<![CDATA[
<img src="https://i.kinja-img.com/gawker-media/image/upload/s--E93LuLOd--/c_fit,fl_progressive,q_80,w_636/hd6cujrvf1d72sbxsbnr.jpg" /><p>With a surprise showing of skill and, at one point, a miracle, the bottom-ranked team in the European <em>League </em>Championship Series will not end the summer winless.<br></p><p><a href="http://compete.kotaku.com/european-league-team-finally-wins-its-first-series-of-t-1797363638">Read more...</a></p>
]]>
</description>
【问题讨论】:
-
你试过
$(this).find('img').attr('src')
标签: javascript jquery xml rss rss-reader