AbdulMuttaqin

Google Trends Keyword Scrapper

Jan 11th, 2019
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <?php
  2. function trends($url) {
  3.     $ch=curl_init();
  4.     curl_setopt($ch, CURLOPT_URL, $url);
  5.     curl_setopt($ch, CURLOPT_REFERER,"https://www.google.com");
  6.     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  7.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
  8.     curl_setopt($ch, CURLOPT_USERAGENT,$_SERVER ['HTTP_USER_AGENT']);
  9.     $result=curl_exec($ch);
  10.     return $result;
  11. }
  12. $url=trends('https://trends.google.com/trends/hottrends/atom/feed?pn=p19');
  13. $trends=new SimpleXmlElement($url);
  14. $data=$trends->channel->item;
  15. for($j=0; $j<count($data); $j++) {
  16.     if($data[$j]->title) {
  17.         echo ucwords(strtolower($data[$j]->title)) .",";
  18.    
  19.     }
  20. }
  21. for($i=0; $i<count($data); $i++) {
  22.     $des=explode(',', $data[$i]->description);
  23.     for($k=0; $k<count($des); $k++) {
  24.         if($des[$k]) {
  25.             echo ucwords(strtolower($des[$k])) . ",";
  26.         }
  27.     }
  28. }
  29. ?>
Add Comment
Please, Sign In to add comment