Forum: Ruby how to return the class content in CSS styling tags using Nokogiri

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Li C. (Guest)
on 2017-03-30 08:00
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')   }


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<TITLE>Page 29</TITLE>

<META http-equiv="Content-Type" content="text/html; charset=GBK">
<DIV style="position:relative;width:1053;height:1309;">
<STYLE type="text/css">

<BODY bgcolor="#FFFFFF" vlink="blue" link="blue" style="margin-top: 0px;
margin-left: 0px;">
<DIV style="position:absolute;top:95;left:122"><nobr><span
<DIV style="position:absolute;top:95;left:248"><nobr><span
class="ft4">Chapter 1</span></nobr></DIV>
<DIV style="position:absolute;top:95;left:420"><nobr><span
class="ft5">Chapter 2 </span></nobr></DIV>


>ruby find_hightlight-tag.rb
>Exit code: 0
This topic is locked and can not be replied to.