Home > other >  How parse a table and extract data for last 6 months Nokogiri
How parse a table and extract data for last 6 months Nokogiri

Time:10-06

Im getting confused at this task. I have a table from a demo bank site(check the screen below). Need to extract data only from only last 6 months. Data table I have tried severeal anwsers from these topics: Parse table using Nokogiri Nokogiri: parse, extract and return <tr> content in HTML table

But im still confused how to extract data only from last 6 months without to extract all data and after to check date.

Is any possbile options to extract data in right way ?

The table class Im using to find table in nokogiri is class="tblInf rowOver".

Table

Code I use:

def get_transactions
  cells = ''
  $b.a(:href => "#/history_operations").click!
  sleep(5)
  $p = Nokogiri::HTML.parse($b.html)
  table = $p.css('#simpleTable0')
  table.search('tr').each do |tr|
    payment_description = tr.search('.paymentDescription').text
    p = payment_description.split('  ',-1)
    for i in p
      puts i.delete('  ')
      end


    # puts cells
  end

CodePudding user response:

Generally, it's helpful if you can post some example HTML rather than a screenshot of the page. Particularly as this task is about parsing HTML.

Why do you need to check the date beforehand? Nokogiri is pretty fast, and I can't imagine the table is so big that checking as you parse will be useful. Having reviewed the Nokogiri docs, I can't see any way to do what you're describing. You'll need to grab the data from the table, and then reject any rows that have a date older than six months.

  • Related