douque9982 2017-06-02 10:54
浏览 560
已采纳

难以解析XML文档“此XML文件似乎没有与之关联的任何样式信息。”

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

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'];
}
}

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?

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.

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

Thanks!

展开全部

  • 写回答

1条回答 默认 最新

  • douci1918 2017-06-11 02:07
    关注

    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");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部