juust ~ php oddities

Unordered list of one element
  • rss
  • begin
  • about
    • vcard
    • WTF is BroJesus
  • php scripts
    • flickr wp widget
    • google multi key serp tool, php script
    • gwt plugin
  • php classes
    • php pagerank class
    • fibonacci class
    • robots.txt parser php class
  • serp
    • serp dashboard wordpress plugin
  • services

php serp scripts

juust | 07/07/2008

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

MSN Serp

  1. $first=1;
  2. $query="php+serp";
  3. $count=50;
  4.  
  5. $xml = @simplexml_load_file("http://search.live.com/results.aspx?q=$query&count=$count&first=$first&format=rss");
  6. foreach($xml->channel->item as $i) echo $i->link."<br />";

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”).

Yahoo Serp

  1.  
  2.         $varkeywords=$_GET["keywords"];
  3.         $vardomain=$_GET["domain"];
  4.        
  5.  
  6.         $strResult='';
  7.         $strHitsResult='';
  8.         $strHitsCount=0;
  9.         $strHits='';
  10.  
  11.         $start = 1;
  12.         $numberofresults = 10;
  13.         for($ii=0; $ii&lt;20; $ii++) {
  14.             $jj=$ii*$numberofresults+1;
  15.             $kk=$jj+$numberofresults;
  16.  
  17.         $vargoogleresultpage = "http://search.yahoo.com/search?p=".urlencode(trim($varkeywords))."&ei=UTF-8&fr=sfp&xargs=0&pstart=1&b=".$jj;
  18.             flush();  
  19.            
  20.             $googleresponse = join("",file($vargoogleresultpage));
  21.         $googlehits = preg_split('/<a class=\”yschttl\” /', $googleresponse, -1, PREG_SPLIT_OFFSET_CAPTURE);
  22.             foreach($googlehits as $googlehit){
  23.             $i++;
  24.             preg_match("/href=\"(.*?)\"/", $googlehit[0], $t, PREG_OFFSET_CAPTURE);
  25.                
  26.                
  27.             if($i > 1){
  28.                 $serp = $i-1;
  29.                 $SearchForDomain = "~".$vardomain."~i";
  30.                     if(preg_match($SearchForDomain, $t[1][0])){
  31.                     $strHitsCount++;
  32.                     $strHits .= $serp .', ';    
  33.                     $strResult=$strResult.$serp."<b><a href=\"".$t[1][0]."\" target=\"_blank\">".$t[1][0]."</a></b><br />";
  34.                     $strHitsResult = $strHitsResult.$serp."<b><a href=\"".$t[1][0]."\" target=\"_blank\">".$t[1][0]."</a></b><br />";
  35.                             } else {
  36.                                     $strResult=$strResult.$serp."</a><a href=\"".$t[1][0]."\" target=\"_blank\">".$t[1][0]."</a><br />";
  37.                                     }
  38.                         }
  39.            }
  40.         }
  41.         echo $strHits.' total = '.$strHitsCount.' <br />';
  42.         echo $strHitsResult;
  43.         echo '<br /><br />full list :<br />';
  44.  
  45.         echo $strResult;

Google SERP

  1.         $varkeywords=$_GET["keywords"];
  2.         $vardomain=$_GET["domain"];
  3.        
  4.  
  5.         $strResult='';
  6.         $strHitsResult='';
  7.         $strHitsCount=0;
  8.         $strHits='';
  9.  
  10.         $start = 1;
  11.         $numberofresults = 100;
  12.         for($ii=0; $ii&lt;11; $ii++) {
  13.             $jj=$ii*100+1;
  14.             $vargoogleresultpage = "http://www.google.com/search?as_q=".urlencode(trim($varkeywords))."&num=".$numberofresults."&start=".$jj."&hl=en&lr=lang_en";
  15.             flush();
  16.            
  17.             $googleresponse = join("",file($vargoogleresultpage));
  18.         $googlehits = preg_split('/class=r><a /', $googleresponse, -1, PREG_SPLIT_OFFSET_CAPTURE);
  19.             foreach($googlehits as $googlehit){
  20.                 $i++;
  21.                 preg_match("/href=\"(.*?)\"/", $googlehit[0], $t, PREG_OFFSET_CAPTURE);
  22.                
  23.                
  24.                 if($i > 1){
  25.                         $serp = $i-1;
  26.                         $SearchForDomain = "~".$vardomain."~i";
  27.                         if(preg_match($SearchForDomain, $t[1][0])){
  28.                             $strHitsCount++;
  29.                             $strHits .= $serp .', ';    
  30.                             $strResult=$strResult.$serp."<b><a href=\"".$t[1][0]."\" target=\"_blank\">".$t[1][0]."</a></b><br />";
  31.                             $strHitsResult = $strHitsResult.$serp."<b><a href=\"".$t[1][0]."\" target=\"_blank\">".$t[1][0]."</a></b><br />";
  32.                             } else {
  33.                                     $strResult=$strResult.$serp."</a><a href=\"".$t[1][0]."\" target=\"_blank\">".$t[1][0]."</a><br />";
  34.                                     }
  35.                         }
  36.            }
  37.         }
  38.         echo $strHits.' total = '.$strHitsCount.' <br />';
  39.         echo $strHitsResult;
  40.         echo '<br /><br />full list :<br />';
  41.  
  42.         echo $strResult;

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

Categories
php, serp
Tags
php, serp, tool
Comments rss
Comments rss
Trackback
Trackback

« google guidelines serp pagerank php seo tool »

One Response to “php serp scripts”

  1. Sandrine says:
    21/05/2009 at 9:34 am

    Hi Juust,

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

    Sandrine

    Reply

Leave a Reply

Click here to cancel reply.

Recent Posts

  • Pagerank sculpting session
  • wish you were here
  • interesting : seo panel
  • availability test
  • Mayday

click me!
rss
Comments rss
Blog Directory
Web Developement Blogs - BlogCatalog Blog Directory
Listed in LS Blogs the Blog Directory and Blog Search Engine
Blog Flux Directory
joopita.com free web directory and search engine
design by jide
sitemap
17240 confirmed spam kills