难以解析XML文档“此XML文件似乎没有与之关联的任何样式信息." [英] Difficulty parsing XML document "This XML file does not appear to have any style information associated with it."

查看:1794
本文介绍了难以解析XML文档“此XML文件似乎没有与之关联的任何样式信息."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去几天,我进行了很多搜索,但我现在辞职寻求帮助.

I've searched a lot over the past few days but i'm now resigning to asking for help.

我正在使用PHP的simplexml_load_file()解析许多新闻网站,我的代码如下....

I'm parsing a number of news websites using PHP's simplexml_load_file(), my code is below....

foreach ($sourceID as $s) {

$xml = simplexml_load_file($s['rss']);

$dateTimeArray = [];

if ($xml != false) {
foreach($xml->channel->item as $item)
{       
    foreach($item->pubDate as $date) {
        $dateTimeArray[] = (string) $date;
    }

    $s['dateTimeList'] = $dateTimeArray;        
}
array_push($source, $s);
} else {

echo 'error '.$s['id'];
}
}

有些站点具有此XML文件似乎没有与之关联的任何样式信息.文档树如下所示."显示在顶部,这与不能正确读取为XML文档有关?

There are some sites that have "This XML file does not appear to have any style information associated with it. The document tree is shown below." displayed at the top, this is something to do with not being correctly read as an XML document?

最终,我的php代码不会解析显示此消息的网站上的任何数据,任何可以轻松添加到我当前代码中的帮助将不胜感激.

Ultimately my php code will not parse any data from the websites that display this message, any help that can be easily added to my present code would be greatly appreciated.

有问题的xml提要之一就是这个 https://cointelegraph.com/rss

One of the xml feeds in question is this one https://cointelegraph.com/rss

谢谢!

推荐答案

通过设置特定的浏览器来解决此问题:

Fixed this by setting a specific browser:

ini_set("user_agent","Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Mobile Safari/537.36");

这篇关于难以解析XML文档“此XML文件似乎没有与之关联的任何样式信息."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆