I’m trying to learn on scrap these values which i put it in 2 different task:
- get the 35.00 from the entire text
- get the 42.00 from the entire text
below is the html:
<p style="font-size: 30px; margin-left: -10px; padding: 15px 0pt;">
$35.00 - $42.00
</p>
the code that im using to get the entire text is as below:
node = html_doc.at_css('p')
p node.text
You can get the whole text from
node.textand that’s as far as you need to go with Nokogiri. From there you could usescanto find the numbers and a bit of list wrangling (flattenandmap) and you’re done. Something like this:That should leave you with 35.0 in
firstand42.0insecond. If you know that the numbers are prices with decimals then you can simplify the regex a bit: