Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Is there an working example for rubyful_soup on RoR?
wellington2013
10/30/2006 6:39:00 AM
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://w...
)
@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
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Is there an working example for rubyful_soup on RoR?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password