php serp scripts

Some basic PHP search engine result page scripts (always come in handy for yer basic seo adventures).

MSN Serp

$first=1;
$query="php+serp";
$count=50;

$xml = @simplexml_load_file("http://search.live.com/results.aspx?q=$query&count=$count&first=$first&format=rss");
foreach($xml->channel->item as $i) echo $i->link."
";

www.tellinya.com has another version for non-simplexml servers (uses curl and the ehttp.client class, the technique is closer to a sequential line parser so sometimes its more practical (hint:blog-pipe parsing with “streams”).

[ad#banner]

Yahoo Serp


        $varkeywords=$_GET["keywords"];
        $vardomain=$_GET["domain"];
       

        $strResult='';
        $strHitsResult='';
        $strHitsCount=0;
        $strHits='';

        $start = 1;
        $numberofresults = 10;
        for($ii=0; $ii<20; $ii++) {
            $jj=$ii*$numberofresults+1;
            $kk=$jj+$numberofresults;

        $vargoogleresultpage = "http://search.yahoo.com/search?p=".urlencode(trim($varkeywords))."&ei=UTF-8&fr=sfp&xargs=0&pstart=1&b=".$jj;
            flush();   
           
            $googleresponse = join("",file($vargoogleresultpage));
        $googlehits = preg_split('/ 1){
                $serp = $i-1;
                $SearchForDomain = "~".$vardomain."~i";
                    if(preg_match($SearchForDomain, $t[1][0])){
                    $strHitsCount++;
                    $strHits .= $serp .', ';    
                    $strResult=$strResult.$serp."".$t[1][0]."
"; $strHitsResult = $strHitsResult.$serp."".$t[1][0]."
"; } else { $strResult=$strResult.$serp."".$t[1][0]."
"; } } } } echo $strHits.' total = '.$strHitsCount.'
'; echo $strHitsResult; echo '

full list :
'; echo $strResult;

[ad#banner]

Google SERP

        $varkeywords=$_GET["keywords"];
        $vardomain=$_GET["domain"];
       

        $strResult='';
        $strHitsResult='';
        $strHitsCount=0;
        $strHits='';

        $start = 1;
        $numberofresults = 100;
        for($ii=0; $ii<11; $ii++) {
            $jj=$ii*100+1;
            $vargoogleresultpage = "http://www.google.com/search?as_q=".urlencode(trim($varkeywords))."&num=".$numberofresults."&start=".$jj."&hl=en&lr=lang_en";
            flush();
           
            $googleresponse = join("",file($vargoogleresultpage));
        $googlehits = preg_split('/class=r> 1){
                        $serp = $i-1;
                        $SearchForDomain = "~".$vardomain."~i";
                        if(preg_match($SearchForDomain, $t[1][0])){
                            $strHitsCount++;
                            $strHits .= $serp .', ';    
                            $strResult=$strResult.$serp."".$t[1][0]."
"; $strHitsResult = $strHitsResult.$serp."".$t[1][0]."
"; } else { $strResult=$strResult.$serp."".$t[1][0]."
"; } } } } echo $strHits.' total = '.$strHitsCount.'
'; echo $strHitsResult; echo '

full list :
'; echo $strResult;

MSN (being microsoft) don’t encourage commercial use of the rss-feed.

Posted in php, serp and tagged , , .

One Comment

  1. Hi Juust,

    I have done almost the same script for yahoo… this morning they banned my ipaddress…
    now im using yahoo boss.

    Sandrine

Leave a Reply

Your email address will not be published. Required fields are marked *