In: , , ,
On: 2003 / 03 / 23
Shorter URL for this post: http://ozh.in/a

This script queries Google and returns the first result (the one you'd get hitting the "I Feel Lucky" button). I did it because I wanted not to use LWP::Simple on a computer where the lib was missing. Consider this as is my minimalistic web client example.
(the fancy stuff that might confuse you, as "print NOTICE", are for a PsyBNC integration. Ignore them)

  1. #!/usr/bin/perl
  2.  
  3. use IO::Socket;
  4. $nick = shift (@ARGV);
  5.  
  6. if ($#ARGV < 0 ) {
  7. print ":g00gle NOTICE $nick :Err…. google what ffs m8 ?\n" ;
  8. exit;
  9. }
  10.  
  11. $host = "www.google.com";
  12. $document = "/search?btnI=\&q=" . join ("+", @ARGV);
  13. $kikoo=0;
  14.  
  15. $EOL = "\015\012";
  16. $BLANK = $EOL x 2;
  17.  
  18. $remote = IO::Socket::INET->new(
  19. Proto => "tcp",
  20. PeerAddr => $host,
  21. PeerPort => "http(80)",
  22. );
  23.  
  24. unless ($remote) { die "cannot connect to http daemon on $host"; }
  25. $remote->autoflush(1);
  26. print $remote "GET $document HTTP/1.0" . $BLANK;
  27. while ( <$remote> ) {
  28. if (m/^location/i ) {
  29. $tutu = $_ ;
  30. $tutu=~s/^location: //i;
  31. print ":g00gle NOTICE $nick :$tutu"; $kikoo = 1;
  32. } ;
  33. }
  34. close $remote;
  35.  
  36. print ":g00gle NOTICE $nick :No result ffs m8 !\n" unless $kikoo;

Shorter URL

Want to share or tweet this post? Please use this short URL: http://ozh.in/a

Metastuff

This entry "Perl google client" was posted on 23/03/2003 at 3:19 pm and is tagged with , , ,
Watch this discussion : Comments RSS 2.0.

No Comment yet

  1. GaSPaRD says:

    C'est bon j'ai reussi, et j'ai fait mon propre script pour google :)
    Voici le lien si ça peux interesser quelqu'un :

    http://scripts.hollywoud.net/perl-psybnc/google.pl.txt

  2. GaSPaRD says:

    Salut, j'aurais aimé savoir ce que tu mettais dans ton Psybnc pour lancer le script perl et renvoyer le resultat sur irc. Merci :)

  3. GaSPaRD says:

    Salut, j'aurais aimé savoir ce que tu mettais dans ton Psybnc pour lancer le script perl et renvoyer le resultat sur irc. Merci :)

  4. GaSPaRD says:

    Désolé pour la répetition :)

  5. Ozh says:

    ca depend si tu veux que le script soit accessible à un user ou a tout le monde
    http://www.psybnc.info/ y'a des exemples des 2 cas

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar and sign for a free account
Spam: Various spam plugins may be activated. I'll put pins in a Voodoo doll if you spam me.

Read more ?