related_words 0.0.0 → 0.0.1
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.
- data/bin/related_words +8 -0
- data/lib/related_words/baidu.rb +18 -0
- metadata +7 -5
data/bin/related_words
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
require 'cgi'
|
3
|
+
module RelatedWords
|
4
|
+
class Baidu
|
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}"
|
8
|
+
response = Typhoeus.get url
|
9
|
+
if response.success?
|
10
|
+
text = response.body.match(/div class="bc relate">(.+?)<\/div>/)[1]
|
11
|
+
return text.scan(/<a .+?>(.+?)<\/a>/)
|
12
|
+
else
|
13
|
+
return nil
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: related_words
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
-
|
8
|
+
- muzik
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-12-28 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
15
|
-
email:
|
14
|
+
description: fetch related words from baidu
|
15
|
+
email: 860577@gmail.com
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/related_words.rb
|
21
|
-
|
21
|
+
- lib/related_words/baidu.rb
|
22
|
+
- bin/related_words
|
23
|
+
homepage: https://gitcafe.com/muzik/related-words
|
22
24
|
licenses: []
|
23
25
|
post_install_message:
|
24
26
|
rdoc_options: []
|