Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 是否可以将Mechanize::文件转换为Mechanize::页面_Ruby_Gem_Mechanize_Mechanize Ruby - Fatal编程技术网

Ruby 是否可以将Mechanize::文件转换为Mechanize::页面

Ruby 是否可以将Mechanize::文件转换为Mechanize::页面,ruby,gem,mechanize,mechanize-ruby,Ruby,Gem,Mechanize,Mechanize Ruby,Mechanize gem有问题,如何将Mechanize::File转换为Mechanize::Page 以下是我的代码: **link** = page.link_with(:href => %r{/en/users}).click 当用户单击链接时,它会转到包含用户列表的页面,现在我想单击第一个用户,但我无法实现这一点,因为链接返回机械化::文件对象 任何帮助,建议都会很好,谢谢只要用nokogiri解析身体: link = page.link_with(:href => %

Mechanize gem有问题,如何将Mechanize::File转换为Mechanize::Page

以下是我的代码:

**link** = page.link_with(:href => %r{/en/users}).click
当用户单击链接时,它会转到包含用户列表的页面,现在我想单击第一个用户,但我无法实现这一点,因为链接返回机械化::文件对象


任何帮助,建议都会很好,谢谢

只要用nokogiri解析身体:

link = page.link_with(:href => %r{/en/users}).click
doc = Nokogiri::HTML link.body
agent.get doc.at('a')[:href]

Mechanize使用内容类型来确定应如何处理资源。有时网站不会为其资源设置mime类型<代码>机械化::文件是未设置内容类型的默认值

如果你只处理
'text/html'
你可以遵循Jimm Stout的使用
post\u connect\u hooks

agent = Mechanize.new do |a|
  a.post_connect_hooks << ->(_,_,response,_) do
    if response.content_type.empty?
      response.content_type = 'text/html'
    end
  end
end
agent=Mechanize.new do|a|
a、 post连接钩子(u,u,响应,u)do
如果response.content\u type.empty?
response.content_type='text/html'
结束
结束
结束

有人知道如何处理这种情况吗?