Jump to content

How to get results from google in text file?


PhpLogLick

Recommended Posts

Well, this is what I would do. (Note, this probably wont work as I am just trying to get across an idea):

$search_string = $_POST['search_string'];
// You need code here for converting the search string found from post into a valid google search url, I
// have no idea how you would do this. Google urls are in this format though:
// http://www.google.com/search?hl=en&q=WORD1+WORD2   etc, although be noted that special
// characters such as " or $ turn into things like '%22d'.
$url = function_for_converting($search_string);
$handle = fopen($url, "r");
if ($handle) {
$contents = stream_get_contents($handle);
fclose($handle);
}
// The code above will return the HTML of the google page. You need to parse this source html for
// the information you need. Google for get_string_between php function, that will get you
// started. I assume you will get each result as an array element
$handle = fopen("googleresults.txt", "w");
if ($handle) {
  foreach ($google_results as $value) {
    fwrite($handle, $value."\r\n");
  }
  fclose($handle);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.