SERP finder and exporter

Status
Not open for further replies.

mmitdd

New member
Jul 30, 2007
30
0
0
Hi guys,

Is there a piece of software where I can add a list of keywords (say 100) and it will search Google for the top 10-100 results for each keyword and return the URLs?

I need to be able to export all that into Excel.

Not sure if any link exchange scripts can do that.

Thanks in advance.
 


I acquired seo elite a while back and it does this fine...though there may well be free versions about.
 
PHP script. Load a file formatted with keywords on seperate lines, it will return an HTML file formatted as
HTML:
keyword1;url1<br>
keyword1;url2<br>
keyword2;url1<br>
keyword2;url2<br>
Any trouble with it let me know.

EDIT: Not optimized for Excel importing. Working on it now...

PHP:
<?php


function getData() {
    $file = '';

    // if form has been submitted 
    if (isset($_POST['file'])) {
        // return POST
        return array($_POST['file'], $_POST['numResults']);
    }
    // if form has not yet been submitted 
    else {
        printForm();
    }
}

function printForm() {
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Enter file <input type="text" name="file"><br>
    Number of results per keyword <input type="text" name="numResults"><br>
    <input type="submit" name="submit" value="Go">
    </form>
    <p>
    <?php
}


function getLinks($keyword, $num)
{
    $data = file_get_contents('http://www.google.com/search?hl=en&as_q='.trim($keyword).'&as_epq=&as_oq=&as_eq=&num='.$num.'&lr=&as_filetype=&ft=i&as_sitesearch=&as_qdr=all&as_rights=&as_occt=any&cr=&as_nlo=&as_nhi=&safe=off');
    $regex = '/\<h3 class=r\>\<a href=\"(.+?)\"/';
    preg_match_all($regex,$data,$match);
    return $match[1];
}

$inputs = getData();

/////////////////////////
if (isset($_POST['file'])) {
//SECOND RUN START HERE//

$keywords = file($inputs[0]);
$numResults = $inputs[1];
$results = array();


foreach($keywords as $currentWord)
{
    $results = getLinks($currentWord, $numResults);
    foreach($results as $url)
    {
        echo trim($currentWord).';'.$url.'<br>';
        print "\n";
    }
}

}
?>
 
My 10-minute edit window is up, so sorry for the double-post.

A couple changes from the old version:

-Uses GET instead of POST, so the results page will have a different URL than the form page. Excel's Web Query tool will now work (only tested on Excel 2002).
-Added several options for the display. "HTML Table" produces an HTML Table. "Semicolon-delimited, source view" produces a page with no HTML formatting. "Semicolon-delimited, HTML view" produces a page with a <br /> at the end of each line, so it's formatted correctly in the browser.

The file chosen must be formatted with one keyword per line. Choosing less than 10 or so results per keyword will give you some bad results, and putting in anything more than 100 will only return 100.

It does no error-checking of any kind. Make sure your inputs are correct. If your keyword file and your number of results take too long to load, the server may time out. You might have to split your keyword files into shorter chunks if this is the case. I got 2121 results and the 21st keyword on a localhost server before timeout after 30 seconds.

If you're familiar with Google's query format, feel free to fiddle with lines 36 and 37. DO NOT leave both of them un-commented. It will make the script access the page twice, you don't want this.

And feel free to ask for help or whatever.

PHP:
<?php


function getData() {
    $file = '';

    // if form has been submitted 
    if (isset($_GET['file'])) {
        // return GET
        return array($_GET['file'], $_GET['numResults'], $_GET['displayType']);
    }
    // if form has not yet been submitted 
    else {
        printForm();
    }
}

function printForm() {
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
    Enter file <input type="text" name="file"><br>
    Number of results per keyword <input type="text" name="numResults"><br>
    Display type: <select name='displayType'>
    <option value="1">HTML Table</option>
    <option value="2">Semicolon-delimited, HTML view</option>
    <option value="3">Semicolon-delimited, source view</option>
    <input type="submit" name="submit" value="Go">
    </form>
    <p>
    <?php
}


function getLinks($keyword, $num)
{
    //$data = file_get_contents('http://www.google.com/search?hl=en&as_q='.trim($keyword).'&as_epq=&as_oq=&as_eq=&num='.$num.'&lr=&as_filetype=&ft=i&as_sitesearch=&as_qdr=all&as_rights=&as_occt=any&cr=&as_nlo=&as_nhi=&safe=off');
    $data = file_get_contents('http://www.google.com/search?hl=en&as_q='.trim($keyword).'&as_epq=&as_oq=&as_eq=&num='.$num);    
    $regex = '/\<h3 class=r\>\<a href=\"(.+?)\"/';
    preg_match_all($regex,$data,$match);
    return $match[1];
}

$inputs = getData();

/////////////////////////
if (isset($_GET['file'])) {
//SECOND RUN START HERE//

$keywords = file($inputs[0]);
$numResults = $inputs[1];
$display = $inputs[2];
$results = array();

if ($display == 1)
{
    echo '<table border="1">';
    print "\n";
}

foreach($keywords as $currentWord)
{
    $results = getLinks($currentWord, $numResults);
    foreach($results as $url)
    {
        if ($display > 1)
        {
            echo trim($currentWord).';'.$url;
            if ($display == 2)
            {
                echo '<br />';
            }
            print "\n";
        }
        else if ($display == 1)
        {
            echo '<tr><td>'.trim($currentWord).'</td><td>'.$url.'</td></tr>';
            print "\n";
        }
    }
}

if ($display == 1)
{
    echo '</table>';
    print "\n";
}

}
?>
 
Hello clorox,

thanks for the script, I have one question though:
Is the keywords list file supposed to be on my server as well?
How exactly do I call it on the first field - do I enter "www.website.com/keywords.txt" ?

Thanks.

And another question to everyone about Adwords Digger:
Did it happen to any of you that the Adwords Digger returned no results?
I'm a massive user of Adwords Digger and I load 100's of queries to check at once and I suspect that Google has blacklisted my IP or my network because of that.

What do you think? Is there any way to deal with it?


Thanks again.
 
Hello clorox,

thanks for the script, I have one question though:
Is the keywords list file supposed to be on my server as well?
How exactly do I call it on the first field - do I enter "www.website.com/keywords.txt" ?

Thanks.

Thanks again.

OK, I got it now and it works.
But I have another question:
I was trying to run a query using the allintitle and site parameters, e.g.:
allintitle:acai site:acaiberry.com

and I got an error message.
Is there any way I can use your script with the parameters above?


Thanks again.
 
@Clorox: Thanks for the code. I might add that it helps to urlencode the keywords if you have spaces. I was getting errors otherwise...
 
Status
Not open for further replies.