related_words 0.0.1 → 0.0.2

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.
@@ -4,5 +4,5 @@
4
4
 
5
5
  require 'pp'
6
6
  require 'related_words'
7
- puts RelatedWords::Baidu.query(ARGV.shift).join("\n")
7
+ puts RelatedWords::Baidu.query(ARGV.shift).inspect
8
8
 
@@ -3,12 +3,11 @@ require 'cgi'
3
3
  module RelatedWords
4
4
  class Baidu
5
5
  def self.query word
6
- url = "http://www.baidu.com/s?wd=#{CGI.escape word}&ie=UTF-8"
7
- url = "http://m.baidu.com/s?word=#{CGI.escape word}"
6
+ url = "http://m.baidu.com/s?word=#{CGI.escape word}&ie=UTF-8"
8
7
  response = Typhoeus.get url
9
8
  if response.success?
10
9
  text = response.body.match(/div class="bc relate">(.+?)<\/div>/)[1]
11
- return text.scan(/<a .+?>(.+?)<\/a>/)
10
+ return text.scan(/word=(.+?)\&/).flatten.collect{|r| CGI.unescape(r)}
12
11
  else
13
12
  return nil
14
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: related_words
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-28 00:00:00.000000000 Z
12
+ date: 2012-12-29 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: fetch related words from baidu
15
15
  email: 860577@gmail.com