1

我正在使用 Google Feed API 将 Feed 解析为 HTML。我正在尝试从contentJSON 的正文中访问第一张图片。这是我现在的脚本:

function parseRSS(url, container) {
  $.ajax({
    url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + encodeURIComponent(url),
    dataType: 'json',
    success: function(data) {
      console.log(data.responseData.feed);
      // $(container).html('<h2>'+capitaliseFirstLetter(data.responseData.feed.title)+'</h2>');

      $.each(data.responseData.feed.entries, function(key, value) {
        var images = $(value.content).find('img').map(function(){
          return $(this).attr('src')
        }).get();

        $(container).append('<article><h3><a href="'+ value.link +'" target="_blank"> '+ value.title +' </a></h3>'+ ( images.length == 0 ? '' : '<img src="'+ images[0] + '"/>' )+'<p>'+ value.contentSnippet +'</p></article>');
      });

    }
  });
}

function capitaliseFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}

它可以很好地获取第二张图像,但不是第一张。有什么建议么?

4

0 回答 0