baidu 1.2.8 → 1.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/baidu.rb +15 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bc31375e4db31f83b62ce356d1e42ffdc7117d3
4
- data.tar.gz: dc8d01a40ad9b1a5f1309acee55b7fba2902a6cc
3
+ metadata.gz: 973532d0e6e0bc141eb17dcd034daccbefe2210a
4
+ data.tar.gz: abdd019318edf7956ca07a7dd1bca44c02faaa1b
5
5
  SHA512:
6
- metadata.gz: a306949dcb4037980ab36530bcf719be371ac45075d99e8a6d1179108f644062ada12c7921ece62b6af73fe9c37744cf86cb7d7f8874da7c5cf04256ccc00072
7
- data.tar.gz: 54f95627585171082e362e6244f6bfc3bb94bb8521cb0ee11b4faf6f5265b3f42bf4089e7e0779223805c931e9ddca98571f67cc496e7735281e36f732d315d5
6
+ metadata.gz: b74a336d56fd97b365db05d095991d49fa7cbf8098c180635afe2b8e16683db51ffa876a1fd855491b7f331574f25a91c3fe80dbdd6f2685517d1b45b9807034
7
+ data.tar.gz: a430a916135a289b1577f3468d43188b3b8c6dc84db7460cd00d3af6f993f913f358d7e8e5d1a87d5a7557db30a1ec85cedec9eb949d3698d17fcd068438c791
@@ -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").page.force_encoding('GBK').encode("UTF-8")
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"))}").page.include?"boxFlash"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baidu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.8
4
+ version: 1.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - seoaqua