Module: WebAgent

Defined in:
lib/web_parser/web_agent.rb

Class Method Summary collapse

Class Method Details

.get(url, opts = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/web_parser/web_agent.rb', line 9

def self.get(url,opts={})
  opts["User-Agent"] ||= "Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.0.15) Gecko/2009102704 Fedora/3.0.15-1.fc10 Firefox/3.0.15"
  uri = URI.parse(url)
  http = Net::HTTP.new(uri.host,(uri.port||80))
  res = nil
  http.start do |http|
    req = Net::HTTP::Get.new(url, opts)  
    res = http.request(req) 
  end
  res           
end