2017-02-22 5 views
0

Раньше я использовал этот код, чтобы получить список Google Hot Trends, но недавно он перестает работать, и он перестает работать на веб-сайте, где я тоже получил этот код. Это простой пример кода:My Google Hot Trends Код PHP больше не работает

<?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>"; 
    } 

    ?> 

Эти ошибки:

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 

Любые идеи, как это исправить? Любая помощь оценивается.

ответ

Смежные вопросы