baidu 1.2.8 → 1.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/baidu.rb +15 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 973532d0e6e0bc141eb17dcd034daccbefe2210a
|
4
|
+
data.tar.gz: abdd019318edf7956ca07a7dd1bca44c02faaa1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b74a336d56fd97b365db05d095991d49fa7cbf8098c180635afe2b8e16683db51ffa876a1fd855491b7f331574f25a91c3fe80dbdd6f2685517d1b45b9807034
|
7
|
+
data.tar.gz: a430a916135a289b1577f3468d43188b3b8c6dc84db7460cd00d3af6f993f913f358d7e8e5d1a87d5a7557db30a1ec85cedec9eb949d3698d17fcd068438c791
|
data/lib/baidu.rb
CHANGED
@@ -67,6 +67,17 @@ class Qihoo < SearchEngine
|
|
67
67
|
uri = URI.join("http://#{Host}/",page.request.path).to_s
|
68
68
|
QihooResult.new(page,uri)
|
69
69
|
end
|
70
|
+
def self.related_keywords(wd)
|
71
|
+
url = "http://rs.so.com/?callback=Search.relate.render&encodein=utf-8&encodeout=utf-8&q="+URI.encode(wd)
|
72
|
+
# uri = URI.join("http://#{Host}/",URI.encode('s?q='+wd)).to_s
|
73
|
+
page = HTTParty.get(url)
|
74
|
+
json_str = page.body.split("(")[1].gsub(/\s\);/) {""}
|
75
|
+
parsed_json = JSON.parse(json_str)
|
76
|
+
# each
|
77
|
+
# parsed_json.map { |q| p q['q']}
|
78
|
+
@related_keywords = parsed_json.map { |q| q['q'] }
|
79
|
+
# @related_keywords ||= @page.search("//div[@id=\"rs\"]//tr//a").map{|keyword| keyword.text}
|
80
|
+
end
|
70
81
|
end
|
71
82
|
|
72
83
|
class QihooResult < SearchResult
|
@@ -233,7 +244,7 @@ class MbaiduResult < SearchResult
|
|
233
244
|
[]
|
234
245
|
end
|
235
246
|
def related_keywords
|
236
|
-
@page.search("div[@class='relativewords_info']/a").map{|a|a.text}
|
247
|
+
@related_keywords ||= @page.search("div[@class='relativewords_info']/a").map{|a|a.text}
|
237
248
|
end
|
238
249
|
=begin
|
239
250
|
#返回当前页中,符合host条件的结果
|
@@ -274,7 +285,7 @@ end
|
|
274
285
|
class Baidu < SearchEngine
|
275
286
|
BaseUri = 'http://www.baidu.com/s?'
|
276
287
|
def suggestions(wd)
|
277
|
-
json = HTTParty.get("http://suggestion.baidu.com/su?wd=#{URI.encode(wd)}&cb=callback").
|
288
|
+
json = HTTParty.get("http://suggestion.baidu.com/su?wd=#{URI.encode(wd)}&cb=callback").force_encoding('GBK').encode("UTF-8")
|
278
289
|
m = /\[([^\]]*)\]/.match json
|
279
290
|
return JSON.parse m[0]
|
280
291
|
end
|
@@ -304,7 +315,7 @@ class Baidu < SearchEngine
|
|
304
315
|
=end
|
305
316
|
|
306
317
|
def popular?(wd)
|
307
|
-
return HTTParty.get("http://index.baidu.com/main/word.php?word=#{URI.encode(wd.encode("GBK"))}").
|
318
|
+
return HTTParty.get("http://index.baidu.com/main/word.php?word=#{URI.encode(wd.encode("GBK"))}").include?"boxFlash"
|
308
319
|
end
|
309
320
|
|
310
321
|
def query(wd)
|
@@ -469,5 +480,4 @@ class BaiduResult < SearchResult
|
|
469
480
|
return false if submit and submit['href'].include?'sitesubmit'
|
470
481
|
return true
|
471
482
|
end
|
472
|
-
end
|
473
|
-
|
483
|
+
end
|