baidu 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/baidu.rb +7 -2
- metadata +1 -1
data/lib/baidu.rb
CHANGED
@@ -105,8 +105,13 @@ class BaiduResult
|
|
105
105
|
@page = page
|
106
106
|
end
|
107
107
|
|
108
|
-
def ranks
|
109
|
-
@ranks ||= @page.search("//table[@class=\"result\"]").map{|table|@page.search("//table[@id=\"#{table['id']}\"]//span[@class=\"g\"]").first}.map{|rank|rank.text unless rank.nil?}
|
108
|
+
def ranks(host=nil)
|
109
|
+
@ranks ||= @page.search("//table[@class=\"result\"]").map{|table|@page.search("//table[@id=\"#{table['id']}\"]//span[@class=\"g\"]").first}.map{|rank|URI('http://'+rank.text.strip.split(/\s/).first).host unless rank.nil?}
|
110
|
+
if host.nil?
|
111
|
+
@ranks
|
112
|
+
else
|
113
|
+
@ranks.each_with_index.map{|h,i| i if !h.nil? and h==host}.compact
|
114
|
+
end
|
110
115
|
end
|
111
116
|
|
112
117
|
#look up a word and get the rank of a uri with $host
|