Created
September 26, 2012 11:56
-
-
Save ttscoff/3787610 to your computer and use it in GitHub Desktop.
Google API Search from STDIN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat | php -r ' | |
$input = trim(file_get_contents("php://stdin")); | |
$terms = urlencode($input); | |
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&filter=1&rsz=small&q=$terms"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_REFERER, "G-LINK"); | |
$body = curl_exec($ch); | |
curl_close($ch); | |
$json = json_decode($body,TRUE); | |
$output = "[$input](".$json["responseData"]["results"][0]["unescapedUrl"].")"; | |
printf("%s",$output);' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat | php -r ' | |
$input = trim(file_get_contents("php://stdin")); | |
$terms = urlencode($input." site:wikipedia.org"); | |
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&filter=1&rsz=small&" | |
. "q=$terms"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_REFERER, "G-LINK"); | |
$body = curl_exec($ch); | |
curl_close($ch); | |
$json = json_decode($body,TRUE); | |
$output = "[$input](".$json["responseData"]["results"][0]["unescapedUrl"].")"; | |
printf("%s",$output);' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment