Created
March 30, 2016 17:31
-
-
Save iaindooley/4823d67c139bdb62088ecf714f7594fd to your computer and use it in GitHub Desktop.
Google Suggest Scraper
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
<?php | |
if(count($_POST)) | |
{ | |
$name = microtime(true).'.txt'; | |
$pid = pcntl_fork(); | |
if($pid) | |
{ | |
die('try here: <a href="out/'.$name.'">'.$name.'</a>'); | |
} | |
else | |
{ | |
//we are the parent | |
$lines = explode(PHP_EOL,$_POST['words']); | |
$out = array(); | |
foreach($lines as $line) | |
{ | |
$out[] = $line; | |
if($content = trim(file_get_contents('http://google.com/complete/search?output=toolbar&q='.urlencode($line)))) | |
{ | |
$xml = simplexml_load_string(utf8_encode($content)); | |
foreach($xml->CompleteSuggestion as $sugg) | |
$out[] = (string)$sugg->suggestion['data']; | |
} | |
} | |
file_put_contents('out/'.$name,implode("\n",array_unique($out))); | |
} | |
} | |
?> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<h2>Google Suggest Tool</h2> | |
<br /> | |
<form action="" method="post"> | |
<textarea name="words" style="width:800px;height:400px;"></textarea> | |
<br /> | |
<input type="submit" /> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment