-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeblio.rb
More file actions
37 lines (34 loc) · 879 Bytes
/
Weblio.rb
File metadata and controls
37 lines (34 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## Weblio.rb
## nikezono.net
## 汎用スクレイパー
## 英語にした
## いずれサーバサイド実装
require 'net/http'
require 'nkf'
require 'uri'
class Weblio
def Weblio::search(w,inputpat,limit=10)
res = []
res << [w[0],inputpat]
w = NKF.nkf('-w',w[0])
Net::HTTP.start('ejje.weblio.jp', 80) {|http|
response = http.get("/english-thesaurus/content/#{w}")
s = response.body.to_s
s = NKF.nkf('-w',s)
s = s.scan(/wdntCL>(.+?)<\/p>/)
puts "s:#{s}"
s.each do |arr|
puts "arr:#{arr}"
text = arr[0].split(',')
puts "text:#{text}"
text.each do |t|
puts "t:#{t}"
res << [t.strip,inputpat]
end
end
}
return res.uniq
end
end
#web = Weblio.new
#Weblio::search("学校",'gakkou')