How to return the class content in CSS styling tags using Nokogiri


Hi all,

I have a webpage containing CSS styling. I know how to use Nokogiri to
extract webpage containing html tags. But not sure if the page contains
CSS styling tags. I wonder if someone out there can give me a clue on

In this simple demo, I want to know which font color is set to these
three classes ft0 ft4 ft5. Then return all classes with font color
set to red.

I can return the name of each class, but I am not sure how to find out
what font color is inside that class.

Thanks in advance,


require ‘nokogiri’
require ‘pp’
doc = Nokogiri::HTML(html)‘span’).each{|tag| puts cl=tag.attr(‘class’) }


Page 29
<!-- .ft0{virtical-align:top;font-size:13px;font-family:Arial;color:#231f20;letter-spacing:0.00000px;} .ft4{virtical-align:top;font-size:13px;font-family:Arial;color:red;letter-spacing:0.00000px;} .ft5{virtical-align:top;font-size:6px;font-family:Arial;color:red;letter-spacing:0.00000px;}


Chapter 1
Chapter 2

ruby find_hightlight-tag.rb
Exit code: 0