15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/searchlink/searches/wikipedia.rb', line 15
def search(_, search_terms, link_text)
body = `/usr/bin/curl -sSL 'https://en.wikipedia.org/wiki/Special:Search?search=#{search_terms.url_encode}&go=Go'`
return false unless body
body = body.force_encoding("utf-8") if RUBY_VERSION.to_f > 1.9
begin
title = body.match(/"wgTitle":"(.*?)"/)[1]
url = body.match(/<link rel="canonical" href="(.*?)"/)[1]
rescue StandardError
return false
end
[url, title, link_text]
end
|