Using Nokogiri I have scraped a page and I am trying to find the total results unsuccessfully.
HTML Fragment (doc)
<div class="total_count">
<b>Returned:</b> 97 results
</div>
Get that total count => 97
doc.search(".total_count").text.gsub(/[^0-9]/,'') #=> 497 !Oops
How can I get past
?
The text it returns is this
doc.search(".total_count").text
"\r\n Returned:\u00A0497\u00A0results\r\n"
So using doc.at(".total_count").text.match('\d+')
gives "496"
The node is
=> [#<Nokogiri::XML::Element:0x1762914 name="div" attributes=[#<Nokogiri::XML::Attr:0x1762878 name=
class" value="total_count">] children=[#<Nokogiri::XML::Text:0x1767618 "\r\n ">, #<Nokogiri::XML
:Element:0x1767e1c name="b" children=[#<Nokogiri::XML::Text:0x1767a98 "Returned:">]>, #<Nokogiri::X
L::Text:0x1767834 "\u00A0497\u00A0results\r\n">]>]
Nokogiri, Ruby Versions
C:\Ruby200>nokogiri -v
DL is deprecated, please use Fiddle
# Nokogiri (1.6.0)
---
warnings: []
nokogiri: 1.6.0
ruby:
version: 2.0.0
platform: i386-mingw32
description: ruby 2.0.0p247 (2013-06-27) [i386-mingw32]
engine: ruby
libxml:
binding: extension
source: system
compiled: 2.8.0
loaded: 2.8.0