Mechanize::Form::Field 文档链接: http://mechanize.rubyforge.org/Mechanize/Form/Field.html
agent = Mechanize.new
page = agent.get("http://localhost/NewTask.aspx")
#获取目标page
submit_form = page.form("aspnetForm")
#通过form name获取目标form
完成如上这几步后返回了页面:
=> #<Mechanize::Form
{name "aspnetForm"}
{method "POST"}
{action "NewTask.aspx"}
[text:0xacef3c type: text name: ctl00$ContentPlaceHolder1$txtNumber value: ]
[text:0xacec78 type: text name: ctl00$ContentPlaceHolder1$txtTime1 value: 2012-05-09 14:02:17]
[textarea:0xacd880 type: name: ctl00$ContentPlaceHolder1$txtValue1 value:]
[selectlist:0xa9c278 type: name: ctl00$ContentPlaceHolder1$cmbPriority value: []]
...
irb(main):011:0> submit_form.ctl00$ContentPlaceHolder1$txtNumber = 1000
SyntaxError: (irb):11: syntax error, unexpected tGVAR, expecting $end
submit_form.ctl00$ContentPlaceHolder1$txtNumber = 1000
^
from C:/Ruby193/bin/irb:12:in `<main>'