1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Google ranking script !

Discussion in 'PHP' started by anandnadaar, Nov 6, 2006.

  1. #1
    Hi Guys,

    I have been running SERP scripts on one of my sites, but all the sudden the Google Ranking tools has stopped working. I am sure on what is wrong in the code for Google, both Yahoo and MSN works fine. but not G. Can anybody suggest what is prob in the script below.

    ------------------------
    <?php
    if ($_GET['url'] != '') {
    if ($_GET['keyword'] != '') {
    $keywords[0] = $_GET['keyword'];
    $url = $_GET['url'];
    $keyword_input = $_GET['keyword'];
    }
    } elseif ($_POST['url'] != '') {
    if (strpos($_POST['keyword'],"\n")) {
    $keywords = str_replace("\n",",",$_POST['keyword']);
    $keywords = explode(",",$keywords);
    } else {
    $keywords[0] = $_POST['keyword'];
    }
    $keyword_input = $_POST['keyword'];
    $url = $_POST['url'];
    }
    $i = 0;
    if ($keywords[$i] != '') {
    while ($keywords[$i] != '') {
    $keyword_implode = str_replace(' ','+',$keywords[$i]);
    $fetch_url = "http://www.google.com/search?num=50&q=" . $keyword_implode . "&btnG=Search";
    ob_start();
    include_once($fetch_url);
    $page = ob_get_contents();
    ob_end_clean();

    $page = str_replace('<b>','',$page);
    $page = str_replace('</b>','',$page);
    //preg_match('/008000\">(.+)<\/font><nobr>/i', $page, $match);
    preg_match_all('/<font color=#008000>(.*)<\/font>/', $page, $match);
    $r = 0;
    $position = '0';
    while ($match[0][$r] != '') {
    if ($position == '0') {
    if (strpos($match[0][$r],$url)) {
    $position = $r+1;
    }
    }
    $r++;
    }
    $google_position = $position;
    ---------------------------------

    The above code searches Google for ranking on a particular keyword. But for some days now it isnt showing up.

    Can anybody suggest !
     
    anandnadaar, Nov 6, 2006 IP
  2. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #2
    2 suspicions...

    1. it seems that your script is scraping the results page - maybe google has changed their format slightly... and some of the anchors you are using have changed?

    2. i have noticed that for google, after a couple of pages, it sometimes seem to be able to suspect that the search is performed by a script/robot instead of a human... it then pops up image verification which will definitely confuse your script...

    i have a similar script for msn ;) - check out my signature...
     
    daboss, Nov 7, 2006 IP
  3. anandnadaar

    anandnadaar Well-Known Member

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Well my tool is here, which has Yahoo and MSN along with Google.. Its only the results from Google that is getting retrived.
     
    anandnadaar, Nov 7, 2006 IP