lib/spidr/agent.rb in spidr-0.1.0 vs lib/spidr/agent.rb in spidr-0.1.1

- old
+ new

@@ -364,10 +364,36 @@ else return @history.include?(URI(url).to_s) end end + # + # Creates a new Page object from the specified _url_. If a _block_ is + # given, it will be passed the newly created Page object. + # + def get_page(url,&block) + host = url.host + port = url.port + + proxy_host = @proxy[:host] + proxy_port = @proxy[:port] + proxy_user = @proxy[:user] + proxy_password = @proxy[:password] + + Net::HTTP::Proxy(proxy_host,proxy_port,proxy_user,proxy_password).start(host,port) do |sess| + headers = {} + + headers['User-Agent'] = @user_agent if @user_agent + headers['Referer'] = @referer if @referer + + new_page = Page.new(url,sess.get(url.path,headers)) + + block.call(new_page) if block + return new_page + end + end + protected # # Returns +true+ if the specified _url_ is queued for visiting, returns # +false+ otherwise. @@ -460,31 +486,9 @@ @link_rules.accept?(url.to_s) end def visit_ext?(url) @ext_rules.accept?(File.extname(url.path)[1..-1]) - end - - def get_page(url,&block) - host = url.host - port = url.port - - proxy_host = @proxy[:host] - proxy_port = @proxy[:port] - proxy_user = @proxy[:user] - proxy_password = @proxy[:password] - - Net::HTTP::Proxy(proxy_host,proxy_port,proxy_user,proxy_password).start(host,port) do |sess| - headers = {} - - headers['User-Agent'] = @user_agent if @user_agent - headers['Referer'] = @referer if @referer - - new_page = Page.new(url,sess.get(url.path,headers)) - - block.call(new_page) if block - return new_page - end end end end