PhpLogLick Posted September 16, 2008 Share Posted September 16, 2008 I want to know how can I get results from google in text file. One search box,where I type what I want then when I got results,script need to record found urls in txt file. Or just print it at current page thanks Quote Link to comment Share on other sites More sharing options...
jamesbrauman Posted September 16, 2008 Share Posted September 16, 2008 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); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.