使用 AngularJS 从<description> RSS 提要中提取图像
Extracting image from <description> RSS feed with AngularJS
我正在尝试学习AngularJS,同时构建一个简单的RSS提要。我设法发出了一个JSON请求并检索了我解析的所有数据,标题,链接,描述和所有RSS。我像这样提取图像:
angular.forEach(feed.entries, function(value){
value.myImage = $(value.content).find('img').eq(0).attr('src');
console.log('image' + value.myImage);
}
但是,有些提要具有不同的结构,而是将图像放置在<content> </content>
像这样,图像放置在<description> </description>
中,如下所示,我正在尝试以这种方式获得它:
angular.forEach(feed.entries, function(value){
value.myImage = $(value.description).find('img').eq(0).attr('src');
console.log('no image' + " " + value.myImage);
});
但是我得到的只是未定义的,所以我无法显示此提要中的图像。我尝试了不同的方法,但我真的很迷茫,我不确定我在这里做错了什么。
我已经在谷歌上搜索并尝试了几个星期。任何帮助都非常感谢!
谢谢:)
这是我得到的 JSON 对象。
Object {feedUrl: "https://www.behance.net/rss", title: "Behance Featured Projects", link: "http://www.behance.net", author: "", description: "The latest projects featured on the Behance"…}
$$hashKey: "027"
author: ""
description: "The latest projects featured on the Behance"
entries: Array[10]
0: Object
$$hashKey: "029"
author: ""
categories: Array[0]
content: "<img src="https://mir-s3-cdn-cf.behance.net/projects/404/2e322a33145177.Y3JvcCw4NzYsNjg0LDAsNzc.jpg" style="float:left;margin-right:15px"><br> Various Illustrations by Patryk Hardziej / 2015"
contentSnippet: " Various Illustrations by Patryk Hardziej / 2015"
link: "https://www.behance.net/gallery/33145177/Various-Illustrations-2015"
publishedDate: "Thu, 28 Jan 2016 08:00:02 -0800"
sImage: undefined
title: "Various Illustrations 2015"
好的,我想我发现它:)
从查询中获取的 HTML 如下所示
<img src="..."> Some text <br/> Some text ...
find 方法仅适用于查找子节点。在这种情况下,img 不是 value.content 的子项,因此它不返回任何内容。
你可以做
angular.forEach(feed.entries, function(value){
// force creation of a root node -> find method should works for all cases
var content = '<div>'+value.content+'</div>';
value.myImage = $(content).find('img').eq(0).attr('src');
console.log('image' + value.myImage);
}
相关文章:
- 无法从 jQuery RSS Feed 中的 localStorage 动态替换类
- 如何使用url加载程序在webpack中导入多个图像
- nodejs-expressjs上传图像并显示它们
- 使用JSP从服务器检索和显示图像
- 角度:在ng重复上切换图像
- 画廊图像未显示
- Phonegap-(安卓/iphone)多个图像的图像库出现问题
- Javascript排序的图像弹出窗口..可以't单独弹出
- 画布数据到图像
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- 使图像在单击时展开到不大于浏览器
- 如何使用 Javascript 和正则表达式将 RSS 提要的描述标签中的多个图像解析到我的描述页面
- 如何检查RSS提要的URL是否存在,否则显示本地图像
- 使用 AngularJS 从
RSS 提要中提取图像 - 正在解析RSS图像JavaScript
- Google Feed API是否支持从RSS提要返回图像?
- 使用javascript (feed API)从rss提要获取图像
- 如何使用javascript/jquery显示带有图像的rss提要
- 处理来自RSS提要的图像src时出错
- 如何使用ionic框架显示RSS提要中的图像