douque9982 2017-06-02 18:54
浏览 548
已采纳

难以解析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 10: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");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面