From martin at malditainternet.com Thu Jul 10 11:51:44 2008 From: martin at malditainternet.com (Martin Sarsale) Date: Thu, 10 Jul 2008 12:51:44 -0300 Subject: [Mechanize-users] custom http headers in form.submit / upload without original form Message-ID: Heyas :) I'm wondering how do I do to send my custom HTTP headers when posting a form. agent.set_headers is a private method and I don't know how to get a reference to HTTPHeaders to use add_field and such. Since my request is a form, I'm sending it using agent.submit(form). Any hints? Bonus question: I would like to upload a file to a REST webservice, but I haven't found the way to do it without first creating a Hpricot form node which IMHO doesn't makes much sense :) thanks in advance! -- Martin Sarsale - martin at malditainternet.com From mat.schaffer at gmail.com Fri Jul 11 00:33:49 2008 From: mat.schaffer at gmail.com (Mat Schaffer) Date: Fri, 11 Jul 2008 00:33:49 -0400 Subject: [Mechanize-users] custom http headers in form.submit / upload without original form In-Reply-To: References: Message-ID: <8E9D32F9-3545-4BE0-94DF-BF085DA36AEB@gmail.com> The most recent version of mechanize should support this by just putting a File object in your post parameters. See: http://github.com/schapht/mechaflickr/tree/master/lib/mechaflickr.rb#L75 For an example. -Mat On Jul 10, 2008, at 11:51 AM, Martin Sarsale wrote: > Heyas :) > > I'm wondering how do I do to send my custom HTTP headers when posting > a form. agent.set_headers is a private method and I don't know how to > get a reference to HTTPHeaders to use add_field and such. > Since my request is a form, I'm sending it using agent.submit(form). > Any hints? > > Bonus question: I would like to upload a file to a REST webservice, > but I haven't found the way to do it without first creating a Hpricot > form node which IMHO doesn't makes much sense :) > > thanks in advance! > > -- > Martin Sarsale - martin at malditainternet.com > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users From anaema_ml at yahoo.fr Thu Jul 17 05:42:23 2008 From: anaema_ml at yahoo.fr (Christophe) Date: Thu, 17 Jul 2008 11:42:23 +0200 Subject: [Mechanize-users] Convert data to utf-8 Message-ID: <487F13FF.1040707@yahoo.fr> Hello, I'm trying to find a solution to convert everything returned by mechanize to utf-8, no matter if the original page is utf-8 or iso and I really don't know where to start from... agent = WWW::Mechanize.new { |a| a.log = Logger.new(File::join(RAILS_ROOT, "log/mechanize.log")) } one_page = agent.get("www.google.fr") My first problem is that one_page encoding should be utf-8 (as stated by firefox page's properties), instead one_page.content_type is "text/html; charset=ISO-8859-1" and displaying text content gives wrong accent conversion. Second problem, when scraping datas from a REAL ISO-8859-1 website, how should I do to convert them to utf-8 ? Mechanize 0.7.6, ruby 1.8.5, CentOS with utf-8 console Thanks From whitethunder922 at yahoo.com Thu Jul 17 10:57:08 2008 From: whitethunder922 at yahoo.com (Matt White) Date: Thu, 17 Jul 2008 07:57:08 -0700 (PDT) Subject: [Mechanize-users] Convert data to utf-8 Message-ID: <911480.12929.qm@web53303.mail.re2.yahoo.com> Christophe, If you're doing this within Rails (which it appears you are), just use string.toutf8. This method is part of the Kconv module which it appears Rails includes by default. Output from my script/console: >> Kconv.toutf8 "string" => "string" >> "string".toutf8 => "string" >> toutf8 HTH, Matt White ----- Original Message ---- From: Christophe To: mechanize-users at rubyforge.org Sent: Thursday, July 17, 2008 3:42:23 AM Subject: [Mechanize-users] Convert data to utf-8 Hello, I'm trying to find a solution to convert everything returned by mechanize to utf-8, no matter if the original page is utf-8 or iso and I really don't know where to start from... agent = WWW::Mechanize.new { |a| a.log = Logger.new(File::join(RAILS_ROOT, "log/mechanize.log")) } one_page = agent.get("www.google.fr") My first problem is that one_page encoding should be utf-8 (as stated by firefox page's properties), instead one_page.content_type is "text/html; charset=ISO-8859-1" and displaying text content gives wrong accent conversion. Second problem, when scraping datas from a REAL ISO-8859-1 website, how should I do to convert them to utf-8 ? Mechanize 0.7.6, ruby 1.8.5, CentOS with utf-8 console Thanks _______________________________________________ Mechanize-users mailing list Mechanize-users at rubyforge.org http://rubyforge.org/mailman/listinfo/mechanize-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From anaema_ml at yahoo.fr Thu Jul 17 11:19:42 2008 From: anaema_ml at yahoo.fr (Christophe) Date: Thu, 17 Jul 2008 17:19:42 +0200 Subject: [Mechanize-users] Convert data to utf-8 In-Reply-To: <911480.12929.qm@web53303.mail.re2.yahoo.com> References: <911480.12929.qm@web53303.mail.re2.yahoo.com> Message-ID: <487F630E.9080005@yahoo.fr> An HTML attachment was scrubbed... URL: