gpt4 book ai didi

Ruby Mechanize gem,从本地 html 副本恢复 Mechanize::Page 对象

转载 作者:行者123 更新时间:2023-12-04 16:18:48 27 4
gpt4 key购买 nike

这是我拥有的代码:

agent = Mechanize.new
page = agent.get 'http://google.com'
page.save 'google_index.htm'

我怎样才能恢复那个 google_index.htmMechanize::Page对象并继续使用该页面,例如。提交,解析等?

我试过做 YAML::dump()Marshal::dump() ,但这似乎是不可能的:
irb(main):024:0> page.class
=> Mechanize::Page

然后:
irb(main):013:0> YAML::dump(page) 
TypeError: can't dump anonymous class Class

和:
irb(main):023:0> Marshal::dump(page)
TypeError: no marshal_dump is defined for class Nokogiri::XML::Element

最佳答案

也许你可以恢复cookies:

agent.cookie_jar.save_as('cookies')
agent.cookie_jar.load('cookies')

不过,您的 session 很有可能会过期。

关于Ruby Mechanize gem,从本地 html 副本恢复 Mechanize::Page 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10653519/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com