Robert Poor
2010-Jul-10 15:47 UTC
[Mechanize-users] parsing a page from a string rather than from get()?
I''m pretty sure this is easy, but haven''t been able to figure it out from the docs or examples: If I already have an HTML page as a string, can I ask Mechanize to parse it into a Mechanize::Page object? As a contrived example: >> page = agent.get("http://www.google.com) => #<Mechanize::Page ...> >> raw_html = page.body => "<!doctype html><html onmousemove=\"google&&google.fade ..." Now: how can I ask Mechanize to parse raw_html back into a Mechanize::Page structure? Thanks in advance.
Aaron Starr
2010-Jul-10 17:17 UTC
[Mechanize-users] parsing a page from a string rather than from get()?
Mechanize::Page.new(nil,{''content-type''=>''text/html''},raw_html,200,Mechanize.new) (For the last argument, you could also use the page''s mechanize object, if you still have it around. Actually, for all the arguments you could use the page''s, if you still have it around.) On Sat, Jul 10, 2010 at 8:47 AM, Robert Poor <rdpoor at gmail.com> wrote:> I''m pretty sure this is easy, but haven''t been able to figure it out from > the docs or examples: If I already have an HTML page as a string, can I ask > Mechanize to parse it into a Mechanize::Page object? > > As a contrived example: > > >> page = agent.get("http://www.google.com) > => #<Mechanize::Page ...> > >> raw_html = page.body > => "<!doctype html><html onmousemove=\"google&&google.fade ..." > > Now: how can I ask Mechanize to parse raw_html back into a Mechanize::Page > structure? > > Thanks in advance. > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20100710/9a4013ee/attachment.html>