Forum: Ruby on Rails Get URL (URI) Process

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ff82af3238a57fbd1212832ec1a19f28?d=identicon&s=25 dylans (Guest)
on 2005-11-12 12:49
(Received via mailing list)
I'm looking for Class or Method that will pass back a document when
given a
URL.
I looked into the URI:: Class, but couldn't find any examples of it's
use.

For example, if I had the URL: http://www.asdf.com/asdf.do?sdf=asdf
... sent the request via GET or POST, and it gave me back an XML
document.

Something like the following would be great:
@doc = SOMECLASS::get(URL, POST)

Any references would be greatly appreciated.
Thanks !
Ce60c4f78a63b0695e4dafc4bd7964f7?d=identicon&s=25 vanek (Guest)
on 2005-11-12 12:49
(Received via mailing list)
perhaps:

   require 'open-uri'
   open( url ).readlines.join

OR

   # Get a web page from a specified URL
   def get(url)
     @uri = URI.parse(url)
     open(url) {|result| @body = result.read }
   end

OR

  require 'htree'
  require 'rexml/document'
  require 'open-uri'

  def read_xhtml_from( uri )
    open( uri ) { |f| HTree.parse f }.each_child do |child|
      if child.respond_to? :qualified_name
        doc = ""; child.display_xml( doc )
        if child.qualified_name == 'html'
          return REXML::Document.new( doc )
        end
      end
    end
  end

Okay, so. How to use it? That nice REXML way you?re already used to.

  html = read_xhtml_from "http://redhanded.hobix.com/"
  html.each_element( "//div[@class='entryFooter']" ) do |e|
    puts e.text( "./a[starts-with(@href,
'http://redhanded.hobix.com/')]" )
  end
[http://redhanded.hobix.com/inspect/noXpathOnMessyH...]
E6dcb4743b83392a4fc39693f110cc26?d=identicon&s=25 eugenol (Guest)
on 2005-11-12 12:49
(Received via mailing list)
On 11/9/05, Dylan Stamat <dylans@gmail.com> wrote:
> I'm looking for Class or Method that will pass back a document when given a
> URL.
>  I looked into the URI:: Class, but couldn't find any examples of it's use.
>

http://rio.rubyforge.org/

rio('http://www.asdf.com/asdf.do?sdf=asdf') >
rio('new_or_existing_file.xml')
Ff82af3238a57fbd1212832ec1a19f28?d=identicon&s=25 dylans (Guest)
on 2005-11-12 12:49
(Received via mailing list)
You guys rock. Thank you very much !
This topic is locked and can not be replied to.