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 ! _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
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]
Dylan Stamat 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.
>
> 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 !
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') _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
You guys rock. Thank you very much ! On 11/8/05, Jérôme L <eugenol-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 11/9/05, Dylan Stamat <dylans-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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'') > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails