我有一个像这样的 API https://blog.com/rss
。它返回以下 xml 作为博客提要。
注意:
我已经看到了这个。但这是针对nodejs应用程序的。
https://github.com/nasa8x/rss-to-json
那么你能告诉我如何检索图像
、标题
、日期
和描述
吗它?即 Json 输出。
之后我需要在 html 页面上显示它,如下所示:
注意:
这只是一个节点。根据 feed 输出,它将有许多节点。即ngFor
循环
.html
<div class="card">
<div class="card-wrapper">
<img class="card-img-top" src="../../../assets/img/blog-1.png" alt="Card image cap">
<div class="card-body">
<h5 class="card-title"> 5 People Management Skills Every Manager Needs</h5>
<span class="card-date">12.12.2018</span>
<p class="card-text">Want to see domain names for sale in your own language? Browse domain names by
languages.</p>
</div>
</div>
https://blog.com/rss
输出:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>
<![CDATA[ Blog ]]>
</title>
<description>
<![CDATA[ All Domain Names are Here: Discover! ]]>
</description>
<link>https://blog.com/</link>
<image>
<url>https://blog.com/favicon.png</url>
<title>Blog</title>
<link>https://blog.com/</link>
</image>
<generator>Ghost 2.2</generator>
<lastBuildDate>Sun, 14 Oct 2018 04:11:06 GMT</lastBuildDate>
<atom:link href="https://blog.com/rss/" rel="self" type="application/rss+xml"/>
<ttl>60</ttl>
<item>
<title>
<![CDATA[ All Domain Names are Here: Discover! ]]>
</title>
<description>
<![CDATA[ <p></p> ]]>
</description>
<link>https://blog.com/all-domain-names-are-here/</link>
<guid isPermaLink="false">5b9b82874af81500bf677bca</guid>
<category>
<![CDATA[ Inside]]>
</category>
<dc:creator>
<![CDATA[ na ]]>
</dc:creator>
<pubDate>Sat, 15 Sep 2018 14:00:00 GMT</pubDate>
<content:encoded>
<![CDATA[ <p></p> ]]>
</content:encoded>
</item>
<item>
<title>
<![CDATA[ Week #39 Report ]]>
</title>
<description>
<![CDATA[
<p>Last week (September 24 - September 30, 2018)</p> <h2 id="spanstylecolor4caf501250000spandomainnameswereregistered"><span style="color:#4CAF50">1,250,000</span> domain names were registered.</h2> <h2 id="spanstylecoloref9a9a850000spandomainnamesweredeleted"><span style="color:#EF9A9A">850,000</span> domain names were deleted.</h2> <hr> <h2 id="topkeywords">TOP KEYWORDS</h2> <ol> <li>home</li> <li>shop</li> <li>online</li> <li>life</li> <li>group</li> <li>tech</li> <li>est</li> <li>one</li> <li>pro</li> <li>man</li> </ol> <p>Kaydedilen alan adlarında en çok geçen kelime “blockchain”. Son zamanlarda sürekli olarak oluşturulan yeni coinler ve sistemlerin</p>
]]>
</description>
<link>https://blog.com/2018-week-39-report/</link>
<guid isPermaLink="false">5bae10de6a7d7900bf5d9be3</guid>
<category>
<![CDATA[ Reports ]]>
</category>
<dc:creator>
<![CDATA[ Author Name ]]>
</dc:creator>
<pubDate>Sat, 01 Sep 2018 16:30:00 GMT</pubDate>
<media:content url="https://blog.com/content/images/2018/10/9.jpg" medium="image"/>
<content:encoded>
<![CDATA[
<img src="https://blog.com/content/images/2018/10/9.jpg" alt="Week #39 Report"><p>Last week (September 24 - September 30, 2018)</p> <h2 id="spanstylecolor4caf501250000spandomainnameswereregistered"><span style="color:#4CAF50">1,250,000</span> domain names were registered.</h2> <h2 id="spanstylecoloref9a9a850000spandomainnamesweredeleted"><span style="color:#EF9A9A">850,000</span> domain names were deleted.</h2> <hr> <h2 id="topkeywords">TOP KEYWORDS</h2> <ol> <li>home</li> <li>shop</li> <li>online</li> <li>life</li> <li>group</li> <li>tech</li> <li>est</li> <li>one</li> <li>pro</li> <li>man</li> </ol> <p>Kaydedilen alan adlarında en çok geçen kelime “blockchain”. Son zamanlarda sürekli olarak oluşturulan yeni coinler ve sistemlerin bu kayıtları motive ettiği söylenebilir.</p> <p>Geçen hafta düşen alan adlarında ise en çok geçen kelime “bet”. Birleşik Devletler’de İslâm’ın yayılması ve halkın kumar gibi kötü alışkanlıkları terk etmesi bunun en büyük sebeplerinden biri.</p> <hr> <h2 id="topextensions">TOP EXTENSIONS</h2> <ol> <li>com</li> <li>top</li> <li>net</li> <li>work</li> <li>org</li> <li>info</li> <li>xyz</li> <li>club</li> <li>online</li> <li>site</li> </ol> <p>Radix Registry’nin yaptığı kampanya ile geçen hafta 100.000 alan adı kaydıyla bir önceki haftaya göre %10 artış yakalayan .tech, bu haftanın en çok göze çarpan ngTLD’si oldu. Kayıtlı alan adları bakımından en yüksek oranda artış gösteren ikinci uzantı ise %5 ile .xyz oldu. Toplam ngTLD sayısı ise 20.000 (%2.5) azaldı.</p> <p>Düşen alan adlarından %6’sı aynı hafta içerisinde tekrar kaydedildi. Kayıtların %10’u backorder servisleri kullanılarak gerçekleştirildi. Yeni kayıtların %30’u GoDaddy aracılığıyla yapıldı. Geçen hafta kaydedilen alan adlarının %50’si .com, %10’u .net, %20’si ccTLD’ler ve %15’i de ngTLD’lerden oluşuyor.</p> <hr> <h2 id="topsales">TOP SALES</h2> <ol> <li>6666666.com - $71,000</li> <li>lucky.io - $67,000</li> <li>tl.net - $40,000</li> <li>kju.com - $14,100</li> <li>mexicanhotels.com $9,465</li> <li>drugwipe.com $7,000</li> <li>japanesehotels.com - $6,755</li> <li>portwein.de - $6,197</li> <li>funeralcare.com - $6,139</li> <li>brainbirds.com $5,824</li> </ol> <hr> <h2 id="othernewsfromtheindustry">OTHER NEWS FROM THE INDUSTRY</h2> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> <p></p>
]]>
</content:encoded>
</item>
</channel>
</rss>
最佳答案
希望您会发现这个库有帮助:
rss-parser: https://github.com/bobby-brennan/rss-parser
- 该库支持 NodeJS 和 web
这是在浏览器中使用回调的示例:
<script src="/node_modules/rss-parser/dist/rss-parser.min.js"></script>
<script>
// Note: some RSS feeds can't be loaded in the browser due to CORS security.
// To get around this, you can use a proxy.
const CORS_PROXY = "https://cors-anywhere.herokuapp.com/"
let parser = new RSSParser();
parser.parseURL(CORS_PROXY + 'https://www.reddit.com/.rss', function(err, feed) {
console.log(feed.title);
feed.items.forEach(function(entry) {
console.log(entry.title + ':' + entry.link);
})
})
</script>
关于javascript - 在 Angular 应用程序上将 XML RSS feed 转换为 Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52840193/