0
我曾經使用這段代碼來獲得谷歌熱門趨勢的列表,但它最近停止了工作,並且它已停止在我也得到此代碼的網站上工作。這是代碼的基本的例子:我的谷歌熱門趨勢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
任何想法如何解決這一問題?任何幫助讚賞。
謝謝。這工作。 –