【问题标题】:simplexml_load_string parser error : AttValue: " or ' expectedsimplexml_load_string 解析器错误:AttValue:" or ' 预期
【发布时间】:2012-08-18 09:38:58
【问题描述】:

解析谷歌天气时出现以下错误。任何人都知道这个问题的解决方案到处都在寻找,但没有任何乐趣

Entity: line 2: parser error : AttValue: " or ' expected

    $lang ='English';
    $place=urlencode($weather);
    $place = utf8_encode($place);
    $url = 'http://www.google.com/ig/api?weather='.$place.',$&hl='.$lang.'';        

    $ch = curl_init();       
    //Set CURL options
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
    $raw_data = curl_exec($ch);
    //close CURL cause we dont need it anymore
    curl_close($ch);         

    $xml = simplexml_load_string($raw_data);

【问题讨论】:

    标签: php xml simplexml


    【解决方案1】:

    google 天气 API is known to 不时抛出 403 错误。发生这种情况时,将使用 HTTP 403 响应和 HTML 错误文档来响应请求。由于错误文档不是有效的 XML,因此您无法使用 simplexml_load_string 对其进行解析。

    你应该使用another weather API

    【讨论】:

    • 为什么他们被禁用了。如果您单击该链接,您会看到有可用数据。
    • 大约一个月前它运行良好 - 我仍然从您提供的链接中获取数据
    • @MatthewChambers 哦,你是对的。它没有被禁用(我认为它会是ones deprecated in 2012 之一)。它只是不时返回 403 错误。目前,我从三个不同的 IP 获得一致的 403。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-23
    • 1970-01-01
    • 2017-10-03
    • 2014-11-08
    • 2012-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多