我知道这适用于我尝试过的其他表单/选择列表。这个特定的似乎不是 ajax。谁能解释一下吗?
# encoding: UTF-8
require 'rubygems'
require 'mechanize'
require 'open-uri'
agent = Mechanize.new
page = agent.get('http://espn.go.com/nba/team/transactions/_/name/bos/boston-celtics')
form = page.form_with(:class => "js-goto")
fields = form.field_with(:class => "tablesm")
puts fields
它应该返回类似 #<Mechanize::Form::SelectList:0x007ffdd3930138>
的内容
最佳答案
该选择列表没有名称属性,这使得它作为表单字段毫无用处。 您仍然可以获得导航 nokogiri 风格所需的数据:
page.at('select.tablesm option[text()="2008"]')[:value]
#=> "http://espn.go.com/nba/team/transactions/_/name/bos/year/2008/boston-celtics"
关于Ruby Mechanize - 无法获取特定的选择列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13850204/