Class: Searcher
- Inherits:
-
Object
show all
- Defined in:
- lib/searcher.rb
Defined Under Namespace
Classes: ChinaSearcher, MultipleCrawler
Constant Summary
collapse
- UsSearchers =
%w(google bing)
- ChinaSearchers =
%w(baidu sogou so360)
- AllSearchers =
UsSearchers + ChinaSearchers
Class Method Summary
collapse
Class Method Details
.baidu ⇒ Object
37
38
39
|
# File 'lib/searcher.rb', line 37
def baidu
@baidu = ChinaSearcher.new('baidu', 'http://www.baidu.com/s?wd=','10')
end
|
.china_searchers ⇒ Object
49
50
51
52
|
# File 'lib/searcher.rb', line 49
def china_searchers
[baidu,sogou,so360]
end
|
.get_infos_from_url(url, selector = 'title') ⇒ Object
29
30
31
|
# File 'lib/searcher.rb', line 29
def get_infos_from_url(url,selector='title')
crawler.fetch(url,selector)
end
|
.get_links_from_searches(keywords, page = 1, searchers = AllSearchers) ⇒ Object
8
9
10
11
12
13
14
15
16
|
# File 'lib/searcher.rb', line 8
def get_links_from_searches(keywords,page=1,searchers=AllSearchers)
infos = []
start_time = Time.now
searchers.each do |searcher|
infos += send 'get_info_from_' + searcher,keywords,page
end
infos << (Time.now - start_time).round(4)
infos
end
|
.so360 ⇒ Object
45
46
47
|
# File 'lib/searcher.rb', line 45
def so360
@so360 = ChinaSearcher.new('so360','http://www.so.com/s?&q=')
end
|
.sogou ⇒ Object
41
42
43
|
# File 'lib/searcher.rb', line 41
def sogou
@sogou = ChinaSearcher.new('sogou', 'http://www.sogou.com/web?query=', '1','page')
end
|