我已经解决了!当form.submit
被调用时,假设最后一个按钮form.buttons
是要使用的按钮。最后一个按钮form.buttons
用于高级表单,因此生成的页面对象是另一个表单,尽管它是更全面的高级搜索表单。
require 'mechanize'
agent = WWW::Mechanize.new
agent.get("https://www.owens.edu/cgi-bin/class.pl/")
agent.page.forms
form = agent.page.forms.last
form.occ_subject = "chm"
result = agent.submit(form, form.buttons.first)
result.parser.css('table.cs-table-settings tr.tbl-class-fill-b td font b').map { |v| v.text.strip }
=> ["Principles of Chemistry", "Principles of Chemistry", "Principles of Chemistry", "Principles of Chemistry", …]
终于我们到了它的底部!HTML 太可怕了,所以您需要为此戴上 XPath 帽子!:)