【问题标题】:Scraping from a slippery .aspx page从光滑的 .aspx 页面中抓取
【发布时间】:2021-12-14 19:14:23
【问题描述】:

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

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

点击“DESCARGAR EXCEL”按钮后,数据以模态(或类似的形式)出现。

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

我使用 ruby​​ 和 Mechanize 进行抓取,但怀疑这不是这里的方法。

【问题讨论】:

    标签: web-scraping


    【解决方案1】:

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

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

    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
    

    【讨论】:

    • 一点也不滑,你说得对。估计我有点瞎。给我未来的自己的建议:if stuck_ligth_at_night? got_to_sleep end
    • 很高兴它有帮助!
    猜你喜欢
    • 2016-09-20
    • 1970-01-01
    • 2021-06-09
    • 1970-01-01
    • 1970-01-01
    • 2016-11-27
    • 2018-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多