从湿滑的.aspx页中刮取

时间:2018-12-14 20:57:21

标签: web-scraping

我需要一些可以在网页弹出窗口中看到的值,但至少就我所知,其来源是未知的。

页面为:https://www.afpmodelo.cl/AFP/Indicadores/Valor-Cuota.aspx

,点击“ DESCARGAR EXCEL”按钮后,数据就会以Modal(或类似方式)显示。

enter image description here

我已经使用Chrome开发工具搜索了源代码和网络XHR,但是找不到数据。

我将红宝石和Mechanize一起使用进行报废,但怀疑这不是去那里的方式。

1 个答案:

答案 0 :(得分:1)

数据正在为我显示在网络工具中。右键单击>检查:

enter image description here

以下代码获取该表(滑动):

require 'mechanize'
require 'nokogiri'

url = 'https://www.afpmodelo.cl/AFP/Indicadores/Valor-Cuota.aspx'

mechanize = Mechanize.new { |agent| 
    agent.user_agent_alias = 'Mac Safari'
}

mechanize.get(url).form_with(:id => 'form1') do |form|
    # submit the form using the DESCARGAR EXCEL button
    data_page = form.submit(form.button_with(:id => 'ContentPlaceHolder1_btn_GRILLA'))

    doc = Nokogiri::HTML(data_page.body)
    results_table = doc.css('div.modal-dialog table')

    # do something with the results_table
    puts results_table
end