下拉菜单刮红宝石

时间:2018-10-05 12:45:52

标签: ruby drop-down-menu screen-scraping mechanize

我正在尝试学习如何使用Ruby查看一个下拉菜单来存储菜单所指向的链接。我正在使用Mechanize gem。 该网站是这样的: http://www.terna.it/SistemaElettrico/TransparencyReport/Load/ActualLoad.aspx

我仅找到此指南: http://ruby.bastardsbook.com/chapters/csurgeries-mechanize/

您能帮我获得每年和每月的链接吗?

谢谢

require 'mechanize'
require 'openssl'
require 'open-uri'

home_url = 'http://www.terna.it/SistemaElettrico/TransparencyReport/Load/ActualLoad.aspx'

SELECT_FIELD_NAMES = {
  'Year'=>'dnn$ctr5810$TernaViewDocumentView$cbAnno',
   'Month' => 'dnn$ctr5810$TernaViewDocumentView$cbMese'
}

#Initialize Mechanize
mech = Mechanize.new
page = mech.get(home_url)

terna_form = page.form('dnn$ctr5810$TernaViewDocumentView$cbAnno')

terna_form = 'ruby mechanize'
puts terna_form
puts mech.page.class    
form = mech.page.forms[0]
puts form.class
puts form.fields.map{|f| f.name}.join("\n")

puts "---------"
year_field ={}

form['name'] = SELECT_FIELD_NAMES["Year"]
puts form['name']

form[SELECT_FIELD_NAMES['Year']] = 2017  


#Submitting a form
list =[]
list = form.submit(form.button_with(:value=>'Cerca'))
list.each do |e|
    puts e
    
end

puts "the end"

0 个答案:

没有答案