Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6993933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:49:38+00:00 2026-05-27T19:49:38+00:00

I have a HTML file with inline CSS: <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01

  • 0

I have a HTML file with inline CSS:

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

<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<DIV style="position:relative;width:612;height:792;">
<STYLE type="text/css">
.ft0{font-size:108px;font-family:Helvetica;color:#000000;}
.ft1{font-size:16px;font-family:Times;color:#000000; }
</STYLE>
</HEAD>
<BODY bgcolor="#A0A0A0" vlink="blue" link="blue">
<DIV style="position:absolute;top:457;left:225"><nobr><span class="ft0">Sample</span>   </nobr></DIV>
<DIV style="position:absolute;top:62;left:241"><nobr><span class="ft1"><b>HTML</b></span></nobr></DIV>
</BODY>
</HTML>

I am trying to parse the inline CSS using Ruby’s css_parser library. Note that the inline CSS has 2 classes .ft0 and .ft1.

My code is:

require 'css_parser'
parser = CssParser::Parser.new
parser.load_file!('filename.html')
puts parser.to_s

Which outputs:

<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>   \n<TITLE>Page 1</TITLE>\n<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<DIV style=\"position:relative;width:612;height:792;\">\n<STYLE type=\"text/css\">\n.ft0 {\nfont-size: 108px; font-family: Helvetica; color: #000000;\n}\n.ft1 {\nfont-size: 16px; font-family: Times; color: #000000;\n}\n" 

when I do:

parser.find_by_selector(".ft0") 

it returns an empty array.

It appears as though css_parser is seeing the entire string


<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML>\n<HEAD>\n<TITLE>Page 1</TITLE>\n<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<DIV style=\"position:relative;width:612;height:792;\">\n<STYLE type=\"text/css\">\n.ft0

as the selector instead of just the class .ft0

Is there a way that I can fix this, so that it just finds the class .ft0?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:49:38+00:00Added an answer on May 27, 2026 at 7:49 pm

    CssParser doesn’t find the target in HTML, it only wants a style-sheet definition. You need to parse the CSS from the HTML then pass it to CssParser.

    This might get you started:

    require 'nokogiri'
    require 'css_parser'
    
    html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE>Page 1</TITLE>
    
    <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <DIV style="position:relative;width:612;height:792;">
    <STYLE type="text/css">
    .ft0{font-size:108px;font-family:Helvetica;color:#000000;}
    .ft1{font-size:16px;font-family:Times;color:#000000; }
    </STYLE>
    </HEAD>
    <BODY bgcolor="#A0A0A0" vlink="blue" link="blue">
    <DIV style="position:absolute;top:457;left:225"><nobr><span class="ft0">Sample</span>   </nobr></DIV>
    <DIV style="position:absolute;top:62;left:241"><nobr><span class="ft1"><b>HTML</b></span></nobr></DIV>
    </BODY>
    </HTML>
    '
    
    doc = Nokogiri::HTML(html)
    
    stylesheet = doc.at('style').content
    parser = CssParser::Parser.new
    parser.add_block!(stylesheet)
    puts parser.find_by_selector(".ft0") 
    

    Which outputs:

    font-size: 108px; font-family: Helvetica; color: #000000;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this in my html file: <html> <head> <title> CMD.exe </title> <link rel=stylesheet
I have a html file that contains urls that start with ftps, http, https,
I have html-file. I have to replace all text between this: [%anytext%]. As I
I have a HTML file that has code similar to the following. <table> <tr>
I have an html file saved in gzip format. The browser displays the html
I have a html file that has invoice details I would like to know
I have a HTML file and a PHP file in the same folder on
I have a HTML file upload field from which I'm reading the file name
I have an HTML file and I want to use javascript to call a
I have a html file that I want to trim. I want to remove

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.