Class: Query::Engine::SMobile

Inherits:
Object
  • Object
show all
Includes:
Query::Engine
Defined in:
lib/query/engine/sm_mobile.rb

Constant Summary collapse

Host =
'm.sm.cn'
Options =
{
  :headers => {"User-Agent" => 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5'}
}

Instance Attribute Summary

Attributes included from Query::Engine

#perpage

Class Method Summary collapse

Methods included from Query::Engine

indexed?

Class Method Details

.query(wd, params = {}) ⇒ Object

基本查询,相当于从搜索框直接输入关键词查询



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/query/engine/sm_mobile.rb', line 11

def self.query(wd, params={})
  q = Array.new
  q << "q=#{URI.encode(wd)}"
  #q << "rn=#{@perpage.to_i}" if @perpage
  # Join arguments
  params.each do |k, v|
    q << "#{k.to_s}=#{v.to_s}"
  end
  uri = URI::HTTP.build(:host=>Host,:path=>'/s',:query=>q.join('&'))
  # begin
    res = HTTParty.get(uri, Options)
    r = Query::Result::SMobile.new(res)
    r.baseuri, r.options = uri, Options  
    r
  # rescue Exception => e
      # warn "#{__FILE__} #{__LINE__} #{uri} fetch error: #{e.to_s}"
      # return false
  # end
end