Comment detail

HTTPでGET その2 (Nested Flatten)

WWW::Mechanizeで.

うちの環境では,timeout 1秒だと成功するorzので,0.1秒にしました.

 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
#!/usr/local/bin/ruby
require 'rubygems'
require 'mechanize'

class Crawler < WWW::Mechanize
  attr_accessor :agent

  PROXY_HOST = 'localhost'
  PROXY_PORT = '8080'
  URI = 'http://ja.doukaku.org/feeds/comments/'

  def initialize(conf = {})
    super()
    self.max_history = 1  # 幸せになるおまじない
    self.set_proxy(PROXY_HOST, PROXY_PORT)
    conf.each {|method, value| self.send(method, value) }
  end

  def fetch
    get(URI)
  end
end

# puts Crawler.new.fetch.body  # => succeed
puts Crawler.new({:open_timeout= => 0.1, :read_timeout= => 0.1}).fetch.body

う,ログインし忘れてた.

Index

Feed

Other

Link

Pathtraq

loading...