i extracting forexfactory calendar. can puts
of td
values it's printing full html tags. how td
value of tag class "calendar__time"?
my code is:
require 'httparty' require 'nokogiri' require 'pry' require 'csv' page = httparty.get('http://www.forexfactory.com/calendar.php?day=aug31.2016') p= nokogiri::html(page) rows=p.css('tr.calendar_row') rows.map |row| puts row.css('td.calendar__date') puts row.css('td.calendar__time') end
when check irb, it's returning tags:
<td class="calendar__cell calendar__time time">9:45pm</td><a href="javascript:void(0);" class="calendarexpanded__graph" data-touchable><span>graph</span></a> </td> </tr> </tbody> </table> </td> </tr> <td class="calendar__cell calendar__date date"></td>
the html snippet tr is:
<tr class="calendar__row calendar_row calendar__row--grey " data-eventid="62529" data-touchable> <td class="calendar__cell calendar__date date"></td> <td class="calendar__cell calendar__time time">2:00am</td> <td class="calendar__cell calendar__currency currency">chf</td> <td class="calendar__cell calendar__impact impact calendar__impact calendar__impact--low"> <div class="calendar__impact-icon calendar__impact-icon--screen"> <span title="low impact expected" class="low"></span> </div> <div class="calendar__impact-icon calendar__impact-icon--print"> <img src="resources/images/icons/impact/impact-yellow.png" alt="" border="0" /> </div> </td> <td class="calendar__cell calendar__event event"> <div> <span class="calendar__event-title">ubs consumption indicator</span> </div> </td> <td class="calendar__cell calendar__detail detail"><a class="calendar__detail-link calendar__detail-link--level-1 calendar_detail level1" data-level="1"></a></td> <td class="calendar__cell calendar__actual actual">1.32</td> <td class="calendar__cell calendar__forecast forecast"></td> <td class="calendar__cell calendar__previous previous"><span class="revised worse" title="revised 1.34">1.21</span></td> <td class="calendar__cell calendar__graph graph"><a class="calendar__detail-link calendar__detail-link--graph-icon calendar_chart"></a></td> </tr> <tr class="calendar__row calendar__expand " data-eventid="62529"> <td> </td> <td colspan="4" class="calendarexpanded__container"> <table class="calendarexpanded"> <tbody> <tr> <td class="calendarexpanded__cell"><strong>actual</strong>1.32</td> <td class="calendarexpanded__cell"><strong>forecast</strong> </td> <td class="calendarexpanded__cell"><strong>previous</strong><span class="revised worse" title="revised 1.34">1.21</span></td> <td class="calendarexpanded__cell calendarexpanded__cell--small"> <a href="javascript:void(0);" class="calendarexpanded__details calendarexpanded__details--1" data-touchable><span>details</span></a> </td> <td class="calendarexpanded__cell calendarexpanded__cell--small">
i got work changing follows:
puts row.css('td.calendar__date').text
Comments
Post a Comment