{"id":33,"date":"2003-03-23T15:19:01","date_gmt":"2003-03-23T13:19:01","guid":{"rendered":"http:\/\/frenchfragfactory.net\/ozh\/archives\/2003\/03\/23\/perl-google-client\/"},"modified":"2007-05-08T13:59:31","modified_gmt":"2007-05-08T11:59:31","slug":"perl-google-client","status":"publish","type":"post","link":"https:\/\/planetozh.com\/blog\/2003\/03\/perl-google-client\/","title":{"rendered":"Perl google client"},"content":{"rendered":"<p>This script queries Google and returns the first result (the one you&#39;d get hitting the &quot;I Feel Lucky&quot; 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.<br \/>\n(the fancy stuff that might confuse you, as &quot;print NOTICE&quot;, are for a PsyBNC integration. Ignore them)<\/p>\n<div id=\"ig-sh-1\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">perl<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"perl\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #666666;font-style: italic\">#!\/usr\/bin\/perl<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000000;font-weight: bold\">use<\/span> IO<span style=\"color: #339933\">::<\/span><span style=\"color: #006600\">Socket<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0000ff\">$nick<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000066\">shift<\/span> <span style=\"color: #009900\">&#040;<\/span><span style=\"color: #339933\">@<\/span><span style=\"color: #000000;font-weight: bold\">ARGV<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #b1b100\">if<\/span> <span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">$#ARGV<\/span> <span style=\"color: #339933\">&lt;<\/span> <span style=\"color: #cc66cc\">0<\/span> <span style=\"color: #009900\">&#041;<\/span> <span style=\"color: #009900\">&#123;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000066\">print<\/span> <span style=\"color: #ff0000\">&quot;:g00gle NOTICE $nick :Err\u00e2\u20ac\u00a6. google what ffs m8 ?<span style=\"color: #000099;font-weight: bold\">\\n<\/span>&quot;<\/span> <span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000066\">exit<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\">&#125;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0000ff\">$host<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #ff0000\">&quot;www.google.com&quot;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0000ff\">$document<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #ff0000\">&quot;\/search?btnI=<span style=\"color: #000099;font-weight: bold\">\\&amp;<\/span>q=&quot;<\/span> <span style=\"color: #339933\">.<\/span> <span style=\"color: #000066\">join<\/span> <span style=\"color: #009900\">&#040;<\/span><span style=\"color: #ff0000\">&quot;+&quot;<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #339933\">@<\/span><span style=\"color: #000000;font-weight: bold\">ARGV<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0000ff\">$kikoo<\/span><span style=\"color: #339933\">=<\/span><span style=\"color: #cc66cc\">0<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0000ff\">$EOL<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #ff0000\">&quot;<span style=\"color: #000099;font-weight: bold\">\\0<\/span>15<span style=\"color: #000099;font-weight: bold\">\\0<\/span>12&quot;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0000ff\">$BLANK<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #0000ff\">$EOL<\/span> x <span style=\"color: #cc66cc\">2<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0000ff\">$remote<\/span> <span style=\"color: #339933\">=<\/span> IO<span style=\"color: #339933\">::<\/span><span style=\"color: #006600\">Socket<\/span><span style=\"color: #339933\">::<\/span><span style=\"color: #006600\">INET<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #000000;font-weight: bold\">new<\/span><span style=\"color: #009900\">&#040;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">Proto <span style=\"color: #339933\">=&gt;<\/span> <span style=\"color: #ff0000\">&quot;tcp&quot;<\/span><span style=\"color: #339933\">,<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">PeerAddr <span style=\"color: #339933\">=&gt;<\/span> <span style=\"color: #0000ff\">$host<\/span><span style=\"color: #339933\">,<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">PeerPort <span style=\"color: #339933\">=&gt;<\/span> <span style=\"color: #ff0000\">&quot;http(80)&quot;<\/span><span style=\"color: #339933\">,<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #b1b100\">unless<\/span> <span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">$remote<\/span><span style=\"color: #009900\">&#041;<\/span> <span style=\"color: #009900\">&#123;<\/span> <span style=\"color: #000066\">die<\/span> <span style=\"color: #ff0000\">&quot;cannot connect to http daemon on $host&quot;<\/span><span style=\"color: #339933\">;<\/span> <span style=\"color: #009900\">&#125;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0000ff\">$remote<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #006600\">autoflush<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #cc66cc\">1<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000066\">print<\/span> <span style=\"color: #0000ff\">$remote<\/span> <span style=\"color: #ff0000\">&quot;GET $document HTTP\/1.0&quot;<\/span> <span style=\"color: #339933\">.<\/span> <span style=\"color: #0000ff\">$BLANK<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #b1b100\">while<\/span> <span style=\"color: #009900\">&#040;<\/span> <span style=\"color: #339933\">&lt;<\/span><span style=\"color: #0000ff\">$remote<\/span><span style=\"color: #339933\">&gt;<\/span> <span style=\"color: #009900\">&#041;<\/span> <span style=\"color: #009900\">&#123;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #b1b100\">if<\/span> <span style=\"color: #009900\">&#040;<\/span><span style=\"color: #009966;font-style: italic\">m\/^location\/i<\/span> <span style=\"color: #009900\">&#041;<\/span> <span style=\"color: #009900\">&#123;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0000ff\">$tutu<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #0000ff\">$_<\/span> <span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0000ff\">$tutu<\/span><span style=\"color: #339933\">=~<\/span><span style=\"color: #000066\">s<\/span><span style=\"color: #339933\">\/^<\/span>location<span style=\"color: #339933\">:<\/span> <span style=\"color: #339933\">\/\/<\/span>i<span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000066\">print<\/span> <span style=\"color: #ff0000\">&quot;:g00gle NOTICE $nick :$tutu&quot;<\/span><span style=\"color: #339933\">;<\/span> <span style=\"color: #0000ff\">$kikoo<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #cc66cc\">1<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\">&#125;<\/span> <span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\">&#125;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000066\">close<\/span> <span style=\"color: #0000ff\">$remote<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000066\">print<\/span> <span style=\"color: #ff0000\">&quot;:g00gle NOTICE $nick :No result ffs m8 !<span style=\"color: #000099;font-weight: bold\">\\n<\/span>&quot;<\/span> <span style=\"color: #b1b100\">unless<\/span> <span style=\"color: #0000ff\">$kikoo<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>Simple web client for google querying<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[2,42,41,9],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","tag-code","tag-google","tag-irc","tag-perl"],"_links":{"self":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":0,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"wp:attachment":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}