In: , , ,
On: 2003 / 03 / 23 Viewed: 30603 times

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)

PERL:
  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;

Related posts

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. You can trackback this post from your own site

No Comment yet

  1. 1
    GaSPaRD France »
    commented, on 15/Aug/04 at 11:09 pm # :

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

  2. 2
    GaSPaRD France »
    commented, on 15/Aug/04 at 11:39 pm # :

    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. 3
    GaSPaRD France »
    commented, on 15/Aug/04 at 11:40 pm # :

    Désolé pour la répetition :)

  4. 4
    Ozh France »
    commented, on 18/Aug/04 at 3:57 pm # :

    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

  5. 5
    GaSPaRD France »
    said, on 08/Oct/04 at 6:39 pm # :

    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

Leave a Reply

Comment Guidelines or Die

  • HTML: You can use these tags: <a href=""> <em> <i> <b> <strong> <blockquote>
  • Posting code: Post raw code (no <> &lt; etc) within appropriate tags : [php][/php], [css][/css], [html][/html], [js][/js], [sql][/sql], [xml][/xml], or generic [code][code]
  • Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar.
  • Spam: Various spam plugins on patrol. I'll put pins in a Voodoo doll if you spam me.
  • I will mark as Spam test comments, all comments with SEO names (ie "My Cool Online Shop" instead of "Joe") or containing forum-like signatures.

Read more ?

Close
E-mail It