Jack Royal-Gordon
2012-May-23 19:40 UTC
[Mechanize-users] Error trying to reload serialized page
What is the correct way to serialize an HTML page gotten from Agent::get, and then to reload the serialized page back into Mechanize? I tried the following code: agent = Mechanize.new p1 = agent.get(url) => #<Mechanize::Page ? > p2 = Mechanize::Page.new(p1.uri.to_s, p1.response.to_s, p1.body) and got the error: Mechanize::ContentTypeError Exception: Mechanize::ContentTypeError I also tried: p2 = Mechanize::Page .new(p1.uri, p1.response, p1.body) and got the error: INTERNAL ERROR!!! undefined method `follow_meta_refresh'' for nil:NilClass /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/whiny_nil.rb:48:in `method_missing'' /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/mechanize-2.4/lib/mechanize/page.rb:350:in `meta_refresh'' /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/mechanize-2.4/lib/mechanize/page.rb:139:in `block (2 levels) in pretty_print'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/prettyprint.rb:199:in `block (2 levels) in group'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/prettyprint.rb:225:in `nest'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/prettyprint.rb:198:in `block in group'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/prettyprint.rb:210:in `group_sub'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/prettyprint.rb:197:in `group'' /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/mechanize-2.4/lib/mechanize/page.rb:138:in `block in pretty_print'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/prettyprint.rb:199:in `block (2 levels) in group'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/prettyprint.rb:225:in `nest'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/prettyprint.rb:198:in `block in group'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/prettyprint.rb:210:in `group_sub'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/prettyprint.rb:197:in `group'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/pp.rb:164:in `object_group'' /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/mechanize-2.4/lib/mechanize/page.rb:134:in `pretty_print'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/pp.rb:154:in `block in pp'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/prettyprint.rb:199:in `block (2 levels) in group'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/prettyprint.rb:225:in `nest'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/prettyprint.rb:198:in `block in group'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/prettyprint.rb:210:in `group_sub'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/prettyprint.rb:197:in `group'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/pp.rb:154:in `pp'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/pp.rb:77:in `block in pp'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/pp.rb:121:in `guard_inspect_key'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/pp.rb:77:in `pp'' /Users/jackrg/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/pp.rb:51:in `pretty_inspect'' /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/commands/eval.rb:47:in `block in execute'' /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/commands/eval.rb:19:in `run_with_binding'' /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/commands/eval.rb:46:in `execute'' /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:280:in `one_cmd'' /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:261:in `block (2 levels) in process_commands'' /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:260:in `each'' /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:260:in `block in process_commands'' /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:253:in `catch'' /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:253:in `process_commands'' /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:173:in `at_line'' (eval):5:in `block in at_line'' <internal:prelude>:10:in `synchronize'' (eval):3:in `at_line'' /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby-debug-base.rb:55:in `at_line'' /Users/jackrg/Documents/Novelty-Stats/prototype/test4.rb:61:in `mechanize_page'' (irb):4:in `irb_binding'' -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20120523/461b6f29/attachment.html>
On May 23, 2012, at 12:40, Jack Royal-Gordon wrote:> What is the correct way to serialize an HTML page gotten from Agent::get, and then to reload the serialized page back into Mechanize? I tried the following code: > agent = Mechanize.new > p1 = agent.get(url) > => #<Mechanize::Page ? > > > p2 = Mechanize::Page.new(p1.uri.to_s, p1.response.to_s, p1.body) > > and got the error: > Mechanize::ContentTypeError Exception: Mechanize::ContentTypeErrorA String is not an acceptable substitute for a Net::HTTPResponse or Hash (representing the headers of a response).> I also tried: > p2 = Mechanize::Page .new(p1.uri, p1.response, p1.body)Try: p2 = Mechanize::Page.new p1.uri, p1.response, p1.body, agent While Mechanize::Page defaults all these to nil, this doesn''t actually work for Page. I''ll see what I can do to fix this.> and got the error: > INTERNAL ERROR!!! undefined method `follow_meta_refresh'' for nil:NilClass > /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/whiny_nil.rb:48:in `method_missing'' > /Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.9.1/gems/mechanize-2.4/lib/mechanize/page.rb:350:in `meta_refresh''A Mechanize instance is consulted to determine how <meta> tags should be found, so you must pass it in.