Is there an working example for rubyful_soup on RoR?

W

wellington2013

I found only Ruby language example to use rubyful_soup.
I don't know if there's a working example for RoR...

Basicall, I've done the following:


in my controller, modified from someone's blog
================================================
class GethttpController < ApplicationController

require 'net/http'
require 'uri'

require 'rubygems'
require 'rubyful_soup'

def fetch(uri_str, limit = 10)
# You should choose better exception.
raise ArgumentError, 'HTTP redirect too deep' if limit == 0

response = Net::HTTP.get_response(URI.parse(uri_str))
case response
when Net::HTTPSuccess then Net::HTTP.get(URI.parse(uri_str))
when Net::HTTPRedirection then fetch(response['location'], limit - 1)
else
response.error!
end
end

def test
@soup=nil
@result=nil
markup=nil
markup = fetch('http://www.ibm.com)
@soup = BeautifulSoup.new(markup)

end

end
================================================
In my view, only one line

Title:<%= @soup.html.head.title.string%>

================================================

the above code can run once and output right data.
But if I refresh my browser, it's not gonna work "again".
and I will encounter error messages

from my log
================================================

ArgumentError (wrong number of arguments (5 for 1)):

C:/InstantRails-1.4-win/InstantRails/ruby/lib/ruby/gems/1.8/gems/rubyful_soup-1.0.4/lib/rubyful_soup.rb:609:in
`initialize'
C:/I
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
DewittMill
Top