2017-02-22 16 views
0

Google Hot Trendsのリストを取得するのにこのコードを使用しましたが、最近は機能しなくなり、このコードもWebサイトで動作しなくなりました。これは、コードの基本的な例です。My Google Hot Trends PHPコードがもう機能しなくなった

Warning: SimpleXMLElement::__construct(): Entity: line 2: parser error : Opening and ending tag mismatch: meta line 1 and HEAD in /home/######/public_html/examples/get_latest_google_trends_with_php/example1.php on line 34 

Warning: SimpleXMLElement::__construct(): <TITLE>301 Moved</TITLE></HEAD><BODY> in /home/######/public_html/examples/get_latest_google_trends_with_php/example1.php on line 34 

Warning: SimpleXMLElement::__construct():^in /home/######/public_html/examples/get_latest_google_trends_with_php/example1.php on line 34 

Warning: SimpleXMLElement::__construct(): Entity: line 6: parser error : Opening and ending tag mismatch: HEAD line 1 and HTML in /home/######/public_html/examples/get_latest_google_trends_with_php/example1.php on line 34 

Warning: SimpleXMLElement::__construct(): </BODY></HTML> in /home/######/public_html/examples/get_latest_google_trends_with_php/example1.php on line 34 

Warning: SimpleXMLElement::__construct():^in /home/######/public_html/examples/get_latest_google_trends_with_php/example1.php on line 34 

Warning: SimpleXMLElement::__construct(): Entity: line 7: parser error : Premature end of data in tag HTML line 1 in /home/######/public_html/examples/get_latest_google_trends_with_php/example1.php on line 34 

Warning: SimpleXMLElement::__construct(): in /home/######/public_html/examples/get_latest_google_trends_with_php/example1.php on line 34 

Warning: SimpleXMLElement::__construct():^in /home/######/public_html/examples/get_latest_google_trends_with_php/example1.php on line 34 

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/######/public_html/examples/get_latest_google_trends_with_php/example1.php:34 Stack trace: #0 /home/######/public_html/examples/get_latest_google_trends_with_php/example1.php(34): SimpleXMLElement->__construct('<HTML><HEAD><me...') #1 {main} thrown in /home/######/public_html/examples/get_latest_google_trends_with_php/example1.php on line 34 

任意のアイデアこの問題を解決する方法:

<?php 

    $url = 'http://www.google.com/trends/hottrends/atom/feed?pn=p1'; 
    $referrer = 'http://www.google.com'; 
    $agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8'; 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 
    curl_setopt($ch, CURLOPT_REFERER, $referer); 
    curl_setopt($ch, CURLOPT_USERAGENT, $agent); 

    $result = curl_exec($ch); 

    $trends = new SimpleXmlElement($result); 

    foreach($trends->channel->item as $value) { 
      echo $value->title."<br>"; 
    } 

    ?> 

は、これらのエラーですか?どんな助けもありがたい。

答えて

関連する問題