i''m writing an app that wants to fetch a URL from a remote server and return the html text file to the app. i''ve been told there are some xml parsers for perl that have request functionality built right in. is there such a thing for Ruby or if nothing else the possibility of using WGET from within a Ruby program. thanks in advance for any help. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
gene.tani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-May-12 18:42 UTC
Re: WGETting from within rails
On May 12, 11:37 am, plewizard <somethingnoonehasthough...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i''m writing an app that wants to fetch a URL from a remote server and > return the html text file to the app. i''ve been told there are some > xml parsers for perl that have request functionality built right in. > is there such a thing for Ruby or if nothing else the possibility of > using WGET from within a Ruby program. > > thanks in advance for any help.you probably want #read in open-uri (or Net::HTTP) http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/index.html or you could just backtick: `curl http::/yourURLhere` --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
plewizard, > i''m writing an app that wants to fetch a URL from a remote server and > return the html text file to the app. i''ve been told there are some If you just want to fetch the page text : require ''open-uri''; html = open("http://yahoo.com").readlines puts html If you need to extract part(s) of the page, use Hpricot require ''rubygems''; require ''open-uri'' require ''hpricot'' doc = Hpricot(open("http://yahoo.com")) title = doc.search(''title'').text body = doc.search(''body'' ).text links = doc .search("a").collect{|a| a[''href''] } puts title puts body puts links.to_yaml Hpricot also lets you modify the page contents : f.ex, doc.search(''a'').each{|link| link.swap(link.inner_html)} turns all the <a href="....">something</a> into something Alain Ravet -------- http://blog.ravet.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---