[英]How to read Image tag src from rss-feed in Angular
我正在努力在 Angular 中获取 rss-feed,我遵循了这种方法。
除了图像标签之外,我能够从我的提要中读取/获取数据。 我的图像标签看起来像这样
<img width="150" height="84" src="https://simply-communicate.com/wp-content/uploads/2013/11/featured.png" alt="ice-dams" />
如何从外壳媒体类型获取 src 标签。
提前致谢。
如果我知道您想要字符串中的图像 src。
您可以使用正则表达式来获取图像 src :
let img = '<img width="150" height="84" src="https://simply-communicate.com/wp-content/uploads/2013/11/featured.png" alt="ice-dams" />'; let regex = /<img.*?src="(.*?)"/; let src = regex.exec(img)[1]; console.log(src);
如果您想获取整个标签外壳元素:
let enclosure = 'some string <enclosure url="https://cinfin.staging.wpengine.com/wp-content/uploads/2020/02/executive-with-client.jpg" length="68284" type="image/jpg" /> some other string'; let regex = /<enclosure(.*?)\\/>/; let src = regex.exec(enclosure)[0]; console.log(src);
然后,如果您想获取所有标签的列表:
let enclosures = 'some string <enclosure url="https://cinfin.staging.wpengine.com/wp-content/uploads/2020/02/executive-with-client.jpg" length="68284" type="image/jpg" /> some other string <enclosure url="https://cinfin.staging.wpengine2.com/wp-content/uploads/2020/02/executive-with-client.jpg" length="68284" type="image/jpg" />'; let regex = /<enclosure(.*?)\\/>/g; let all = enclosures.match(regex); console.log(all);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.