如何从Blogspot的提要中获取数据?

问题描述 投票:0回答:1

[嗨,我想将帖子供稿放到HTML页面上...要获取帖子,我使用以下链接:“ https://www.blogger.com/feeds/bloggerID/posts/default?max-results=N”其中bloggerID是博客ID,N是帖子数当我将链接放在浏览器上时,我得到:

<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="https://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:georss='http://www.georss.org/georss' xmlns:thr='http://purl.org/syndication/thread/1.0' xmlns:blogger='http://schemas.google.com/blogger/2008'><id>tag:blogger.com,1999:blog-614640065733671379</id><updated>2019-12-08T16:30:37.161-08:00</updated><title type='text'>Angélica Abadia Paulista Ribeiro</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://www.blogger.com/feeds/614640065733671379/posts/default?max-results=3'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/614640065733671379/posts/default?max-results=3'/><link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='https://www.blogger.com/feeds/614640065733671379/posts/default'/><link rel='alternate' type='text/html' href='http://angelribeirocomp.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>AngelRibeiro</name><email>[email protected]</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='18' height='32' src='//4.bp.blogspot.com/-HCajnihNU-o/Uzoge8-ME2I/AAAAAAAABdo/x_XEG0duaZQ/s32/*'/></author><generator version='7.00' uri='https://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>3</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-614640065733671379.post-3449800807582452116</id><published>2019-11-27T09:43:00.003-08:00</published><updated>2019-12-08T16:28:04.059-08:00</updated><title type='text'>teste3</title><content type='html'>&lt;div style="background-color: white; font-family: sans-serif; font-size: 14px; line-height: inherit; margin-bottom: 0.5em; margin-top: 0.5em;"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://www.surveycto.com/wp-content/uploads/2018/04/ai-and-dev.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" data-original-height="449" data-original-width="800" height="179" src="https://www.surveycto.com/wp-content/uploads/2018/04/ai-and-dev.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;asdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfaasdfasdfasdfasdfa&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='https://angelribeirocomp.blogspot.com/feeds/3449800807582452116/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='https://angelribeirocomp.blogspot.com/2019/11/teste3.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/614640065733671379/posts/default/3449800807582452116'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/614640065733671379/posts/default/3449800807582452116'/><link rel='alternate' type='text/html' href='https://angelribeirocomp.blogspot.com/2019/11/teste3.html' title='teste3'/><author><name>AngelRibeiro</name><email>[email protected]</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='18' height='32' src='//4.bp.blogspot.com/-HCajnihNU-o/Uzoge8-ME2I/AAAAAAAABdo/x_XEG0duaZQ/s32/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-614640065733671379.post-4548548846718831705</id><published>2019-11-27T09:43:00.001-08:00</published><updated>2019-11-27T09:43:38.892-08:00</updated><title type='text'>teste 2</title><content type='html'>sdfsdfsdf</content><link rel='replies' type='application/atom+xml' href='https://angelribeirocomp.blogspot.com/feeds/4548548846718831705/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='https://angelribeirocomp.blogspot.com/2019/11/teste-2.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/614640065733671379/posts/default/4548548846718831705'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/614640065733671379/posts/default/4548548846718831705'/><link rel='alternate' type='text/html' href='https://angelribeirocomp.blogspot.com/2019/11/teste-2.html' title='teste 2'/><author><name>AngelRibeiro</name><email>[email protected]</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='18' height='32' src='//4.bp.blogspot.com/-HCajnihNU-o/Uzoge8-ME2I/AAAAAAAABdo/x_XEG0duaZQ/s32/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-614640065733671379.post-3986601118136760026</id><published>2019-11-27T03:07:00.001-08:00</published><updated>2019-11-27T03:07:02.420-08:00</updated><title type='text'>Teste</title><content type='html'>Teste</content><link rel='replies' type='application/atom+xml' href='https://angelribeirocomp.blogspot.com/feeds/3986601118136760026/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='https://angelribeirocomp.blogspot.com/2019/11/teste.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/614640065733671379/posts/default/3986601118136760026'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/614640065733671379/posts/default/3986601118136760026'/><link rel='alternate' type='text/html' href='https://angelribeirocomp.blogspot.com/2019/11/teste.html' title='Teste'/><author><name>AngelRibeiro</name><email>[email protected]</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='18' height='32' src='//4.bp.blogspot.com/-HCajnihNU-o/Uzoge8-ME2I/AAAAAAAABdo/x_XEG0duaZQ/s32/*'/></author><thr:total>0</thr:total></entry></feed>

所以我如何获得标题和图像,内容以及帖子的链接?我正在使用的代码如下:

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        myFunction(this);
    }
};
xhttp.open("GET", "https://www.blogger.com/feeds/614640065733671379/posts/default?max-results=3", true);
xhttp.send();

function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagName('author')[0];
    var y = x.childNodes[0];
    document.getElementById("gd:image").innerHTML =
    y.nodeValue; 
}
</script>

</body>
</html>

非常感谢

html xml blogger
1个回答
0
投票

为了从Blogger提要中获取博客数据,建议您使用JSON提要而不是XML提要,因为它既轻巧又快捷。

alt=json参数添加到Feed网址

https://www.blogger.com/feeds/614640065733671379/posts/default?alt=json&max-results=3

以下代码显示了最近三篇文章的数据:

<div id="demo"></div>

<script>
function getPosts(json) {
	var list = [];
	var data = json.feed.entry
	for (var i = 0; i < data.length; i++) {
		var img = data[i].media$thumbnail ? "<img src'" + data[i].media$thumbnail.$t + "'>" : "";
		list.push("<div><a href='"+ data[i].link.pop().href + "'>" + img + data[i].title.$t + "</a></div>");
	}
	document.getElementById('demo').innerHTML = list.join('');
}
</script>

<script src="https://www.blogger.com/feeds/614640065733671379/posts/default?alt=json&max-results=3&callback=getPosts"></script>
© www.soinside.com 2019 - 2024. All rights reserved.