Get URL (URI) Process


#1

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 !


#2

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/noXpathOnMessyHtmlIsJustAsEasyInRuby.html]


#3

On 11/9/05, Dylan S. removed_email_address@domain.invalid 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’)


#4

You guys rock. Thank you very much !