]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
search plugin: update google search
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 28 Aug 2009 11:02:29 +0000 (13:02 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 28 Aug 2009 11:02:29 +0000 (13:02 +0200)
data/rbot/plugins/search.rb

index 3b0fac5fed866344a32958c2dc0ea133cdfa7829..595dab3c732625a91144ff7ce995dd5c2ba1e747 100644 (file)
@@ -17,7 +17,8 @@
 
 GOOGLE_SEARCH = "http://www.google.com/search?oe=UTF-8&q="
 GOOGLE_WAP_SEARCH = "http://www.google.com/m/search?hl=en&q="
-GOOGLE_WAP_LINK = /<a accesskey="(\d)" href=".*?u=(.*?)">(.*?)<\/a>/im
+# GOOGLE_WAP_LINK = /<a accesskey="(\d)" href=".*?u=(.*?)">(.*?)<\/a>/im
+GOOGLE_WAP_LINK = /<a href="(?:.*?u=(.*?)|(http:\/\/.*?))">(.*?)<\/a>/im
 GOOGLE_CALC_RESULT = %r{<img src=/images/calc_img\.gif(?: width=40 height=30 alt="")?>.*?<h2 class=r[^>]*><b>(.+?)</b>}
 GOOGLE_COUNT_RESULT = %r{<font size=-1>Results <b>1<\/b> - <b>10<\/b> of about <b>(.*)<\/b> for}
 GOOGLE_DEF_RESULT = %r{<p> (Web definitions for .*?)<br/>(.*?)<br/>(.*?)\s-\s+<a href}
@@ -91,10 +92,11 @@ class SearchPlugin < Plugin
     end
     single ||= (results.length==1)
     urls = Array.new
+    n = 0
     results = results[0...hits].map { |res|
-      n = res[0]
+      n += 1
       t = Utils.decode_html_entities res[2].gsub(filter, '').strip
-      u = URI.unescape res[1]
+      u = URI.unescape(res[0] || res[1])
       urls.push(u)
       single ? u : "#{n}. #{Bold}#{t}#{Bold}: #{u}"
     }.join(" | ")