1

Google Weather の解析中に以下のエラーが発生します。誰もがこれに対する解決策を知っていますが、喜びはありません

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);
4

1 に答える 1

2

Google Weather APIは、時々 403 エラーをスローすることが知られています。 その場合、リクエストは HTTP 403 レスポンスと HTML エラー ドキュメントで応答されます。エラー ドキュメントは有効な XML ではないため、 で解析できません。simplexml_load_string

別の天気 APIを使用する必要があります。

于 2012-08-18T09:44:56.153 に答える