本文介绍了simplepie不解析谷歌新闻的RSS提要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码可与任何其他rss feed完美配合,但不适用于google news feed.我不知道自己在做什么错,我认为这是一些错误.当我尝试阅读Google新闻供稿时,我一直收到此错误

This code works perfectly with any other rss feed but not with google news feeds. I do not know what I am doing wrong, I think it's some bug.I keep getting this error when I try to read google news feeds

This XML document is invalid, likely due to invalid characters. XML error: SYSTEM or PUBLIC, the URI is missing at line 1, column 61

例如,如果我们尝试使用http://stackoverflow.com/feeds供稿,则效果很好,但不适用于Google新闻供稿.有人可以给我提示吗?

For example if we try the http://stackoverflow.com/feeds feeds it works nicely, but not with google news feeds. Can some one give me a hint?

<?php

    //get the simplepie library
    require_once('simplepie.inc');

    //grab the feed
    $feed = new SimplePie();

    $feed->set_feed_url("http://news.google.com/news?hl=en&gl=us&q=austria&ie=UTF-8&output=rss");
    $feed->force_feed(true);
    //$feed->encode_instead_of_strip(true);


    //enable caching
    $feed->enable_cache(true);

    //provide the caching folder
    $feed->set_cache_location('cache');

    //set the amount of seconds you want to cache the feed
    $feed->set_cache_duration(1800);

    //init the process
    $feed->init();

    //let simplepie handle the content type (atom, RSS...)
    $feed->handle_content_type();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>simple</title>
</head>

<body>
<div id="page-wrap">

    <h1>News Finder</h1>

    <?php if ($feed->error): ?>
      <p><?php echo $feed->error; ?></p>
    <?php endif; ?>

    <?php foreach ($feed->get_items() as $item): ?>

        <div class="chunk">

            <h4 style="background:url(<?php $feed = $item->get_feed(); echo $feed->get_favicon(); ?>) no-repeat; text-indent: 25px; margin: 0 0 10px;"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h4>

            <p class="footnote">Source: <a href="<?php $feed = $item->get_feed(); echo $feed->get_permalink(); ?>"><?php $feed = $item->get_feed(); echo $feed->get_title(); ?></a> | <?php echo $item->get_date('j M Y | g:i a T'); ?></p>



        </div>

    <?php endforeach; ?>


</div>

推荐答案

确保您使用的是 SimplePie 1.2.1 ,1.2中有一个URL解析错误,可能会导致这种类型的错误.

Make sure you're using SimplePie 1.2.1, 1.2 had a bug with URL parsing which can cause this type of error.

(我也是SimplePie首席开发人员,请随时直接向我的电子邮件发送问题)

(I'm also the SimplePie lead developer, so feel free to shoot questions straight to my email)

如果您使用的是1.2.1,则这似乎是错误#162的体现. ,目前尚未确认.我将对此进行深入研究,但这似乎绝对是SimplePie中的错误,而不是您的代码中的错误.

If you are using 1.2.1, it would appear that this is a manifestation of bug #162 which is currently unconfirmed. I'll take an indepth look into this, but it appears to definitely be an error in SimplePie, not in your code.

(我还会在这里回过头说明为什么出于好奇而发生这种情况.)

(I'll also post back here with why this is occurring for the curious amongst you.)

这篇关于simplepie不解析谷歌新闻的RSS提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-21 13:53