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


#1

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
this.

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,

#3/28/2017
#color:red;

require ‘nokogiri’
require ‘pp’

html=DATA.read
doc = Nokogiri::HTML(html)
doc.search(‘span’).each{|tag| puts cl=tag.attr(‘class’) }

END

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;}

–>

2
Chapter 1
Chapter 2

ruby find_hightlight-tag.rb
ft0
ft4
ft5
Exit code: 0