Get latest google trends with php
Get latest google trends with php
Here we come to the fact that if you want traffic to your website it would be good to create posts about the subjects that people search the most which will lead to more visitors and visitors are money.I needed an automated way to extract google trends on hourly bases and store in my database so I can then use them. Google does not provide API for this so here is a script that scrapes google feed and extracts the keywords.
<?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, $referrer);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$result = curl_exec($ch);
$trends = new SimpleXmlElement($result);
foreach($trends->channel->item as $value) {
echo $value->title."<br>";
}
?>
Source from: http://agichevski.com/2013/08/17/get-latest-google-trends-with-php/
留言
張貼留言