php - Easiest way of getting the numbers of hits for a keyword off Google programmatically -
i'm writing html/javascript/php based web application allows users type in random keyword , get returned number of hits keyword generate when searched on google.com
i know can achieved number of different approaches, want though, simplest way of doing this.
what best approach be here, if take allow error marginal of 2%? show sample code?
approach 1: screen scrapinguse php , file_get_contents
this
$keyword = "football"; $html = file_get_contents("http://www.google.com/?q=" . rawurlencode($keyword)); preg_match('/results: - \d+ of ([0-9,]+) for/', $html, $reg); var_dump($reg[1]);
but doesn't quite me , guess violate google's terms of use? implications of be?
approach 2: google ajax apiuse google ajax api , estimatedresultscount
property in json. don't know how if argue improve approach, please provide me sample code i'll idea?
other approaches? i'm looking here concrete, more precise answers what techneques utilize , how utilize them. again, please provide sample code sake of clarity.
go approach 2, using google's api.
i'd recommend checking out jquery, $.ajax function, , playing around api in jsfiddle.net @ first.
php javascript json screen-scraping
No comments:
Post a Comment