我在我的Ruby on Rails应用程序中使用Mechanize和Nokogiri来刮擦我们的本地打印机管理面板,以检索打印机生命周期中的打印页数。机械化陷入Javascript重定向页面
我有以下的rake任务:
# Logs into printer admin page and retrieved counts.
require 'rubygems'
require 'mechanize'
require 'logger'
# Create a new mechanize object
agent = Mechanize.new
# Load the printer admin page
page = agent.get("http://192.168.1.126/index.html?lang=1")
# Select the form with an action of index.cqi
form = agent.page.form_with(:action => "index.cgi")
form.radiobuttons_with(:id => '0x3fdb24153404')[1]
# Submit the form
page = form.submit form.buttons.first
pp page
返回以下内容:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<script type="text/javascript">
<!--
window.onload=function(){setTimeout(function(){document.menu_link.submit();},0);}
//-->
</script>
</head>
<body>
<form name="menu_link" action="index.html" method="post" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="lang" value="1">
</form>
</body>
</html>
我似乎不能够选择上述网页的形式,和脚本似乎停止在该页面,不遵循重定向。
有没有使用这种重定向的标准方式?也许暂停脚本直到重定向发生?它是否每个都允许重定向工作?
任何指针,将不胜感激!
你如何在第二页中选择表格? – Christian 2012-04-22 12:18:47
我刚刚选择了名称为menu_link的表单。 – dannymcc 2012-04-22 15:17:34