Free Script To Save You Time Researching Keywords

9 replies
I was reading yesacpow's thread on ramping up your clickbank commissions the other day (http://www.warriorforum.com/adsense-...step-step.html).

Most of it is pretty quick and easy, but then it's a bit of a pain when you have to google each phrase to see how many results each are, then type them into a spreadsheet (steps 5 and 6).

So I decided to knock up a script and share it with you.

Here's what you do.

1. Cut and paste the code into a file and save it as 'scrapegoogleresults.php'.

2. Change the $google and $country variables to whatever google/country you want to use. Or, just leave them at the US settings.

3. Load it up onto your server. If you don't have a server you can use xampp (which is a group of programs that allows you to turn your pc into a server).

You only need to do that once. To get your results.

1. Put the phrases into a file called 'search.txt' and save it to the server where scrapegoogleresults.php is. One phrase per line. Make sure there is nothing else on that line except the phrase. With no quotes too.

2. Go to http://yourserver/scrapegoogleresults.php

3. The script will get the results for each phrase and put them in a file called 'results.csv'.

4. Open results.csv up in Excel.

Et Voila! Loads of results in less than a minute, all in a format you can easily use.


I'm thinking about uploading this to my server and allowing you to cut and paste your phrases, and it outputs a csv for you to save. What do you think?

Here's the code for those who want to DIY

Code:
<?php
    $cr = "\n";
    $inFile = "search.txt";
    $fh = fopen($inFile, 'r');
    $searchstringin = fgets($fh);
    $google = 'http://www.google.com';
    $country = 'US';
    while ($searchstringin !=""){
        $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
        $searchstringin = str_replace($newlines, "", $searchstringin);
        $searchstring = str_replace(" ", '+', $searchstringin);
        $url = $google.'/search?hl=en&q=%22' . $searchstring . '%22&btnG=Search&meta=&gl='.$country;
        $raw = file_get_contents($url);
        $content = str_replace($newlines, "", html_entity_decode($raw));
        $cr = "\n";
        $start = strpos($content,'Results <b>1</b> - <b>10</b> of about');
        $start = $start +37;
        $end = strpos($content,'</b> for ',$start);
        $results = substr($content,$start,$end-$start);
        $remove = array("<b>",",");
        $results = str_replace($remove, "", $results);
        $text = $searchstringin . "," . $results . $cr;
        echo $searchstringin,",".$results."<br>";
        $out = fopen("results.csv", "a"); 
        if (!$out) {
            print("Could not append to file");
            exit;
        }
        fputs ($out,implode,("\n"));
        fwrite($out,$text);
        fclose($out);
        $searchstringin = fgets($fh);
        sleep(4);
    }
?>
Give me a shout if you get stuck!

Mike
#free #keywords #researching #save #script #time
  • Profile picture of the author melanied
    Great share, thanks! A quick and easy way to do this for free, for the technically inclined.
    Signature
    {{ DiscussionBoard.errors[783732].message }}
  • Profile picture of the author Mr McDonald
    Excellent this will be useful for a great number of people. Posts like this make warrior forum so special.
    {{ DiscussionBoard.errors[783751].message }}
    • Profile picture of the author Martin Avis
      This is a useful script, but a word of warning ...


      If you interrogate Google to quickly, or too often, they will detect the automated search and will block your IP address. Usually their blocks are temporary and are removed after an hour or so, but I have known them to persist for a week or two. During that time you will have to enter a captcha to perform a regular google search, but the PHP script can't do that, so will not work.

      To minimise risk, limit the search string files to ten lines, and perhaps write a delay loop into the code to make a pause of 3 - 5 seconds between each hit on Google.

      Martin
      Signature
      Martin Avis publishes Kickstart Newsletter - Subscribe free at http://kickstartnewsletter.com
      {{ DiscussionBoard.errors[783780].message }}
  • Profile picture of the author Anomaly1974
    I copied the script and I definitely think it is something I could use but I am a writer, not a techie. I have been doing much better at installing my own scripts but I wonder, would it be possible to change the name? Google is actually the top visitor to my site ... or their bots and spiders are at least and even before I update any sitemaps, they have found most of the pages. I wonder however, if they would not frown on finding scrapegoogle anything, but much more so with a php file? I did not see anything in the script that would leave me to believe that it could not be done but before I go messing everything up ... it seems more prudent to ask a question that may be stupid than to fix a problem caused by sheer stupidity!

    Thanks!
    Signature

    “They did not know it was impossible so they did it”
    -Samuel Clemens" (As Mark Twain)

    {{ DiscussionBoard.errors[822654].message }}
  • Profile picture of the author danmorton
    Mike -

    Thanks - will give it a try shortly!

    Very nice to share with the rest of us.

    Dan
    {{ DiscussionBoard.errors[824965].message }}
  • Profile picture of the author Anomaly1974
    Thanks!

    I will definitely be checking it out today or tomorrow. A lot on my plate for the moment but it does look like a time saver ... which is exactly what I need at the moment.

    Ward
    Signature

    “They did not know it was impossible so they did it”
    -Samuel Clemens" (As Mark Twain)

    {{ DiscussionBoard.errors[824979].message }}

Trending Topics