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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
73700e119917433681f2e8f3e4369f74?d=identicon&s=25 Li CN (alex-osu3)
on 2017-03-30 06: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
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__

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<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">
<!--
  .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;}

-->
</STYLE>
</HEAD>
<BODY bgcolor="#FFFFFF" vlink="blue" link="blue" style="margin-top: 0px;
margin-left: 0px;">
<DIV style="position:absolute;top:95;left:122"><nobr><span
class="ft0">2</span></nobr></DIV>
<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>

</BODY>
</HTML>


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