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 8774639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:37:09+00:00 2026-06-13T18:37:09+00:00

Can anyone help with extraction of CSS styles from HTML using Jsoup in Java.

  • 0

Can anyone help with extraction of CSS styles from HTML using Jsoup in Java.
For e.g in below html i want to extract .ft00 and .ft01

<HTML>
<HEAD>
<TITLE>Page 1</TITLE>

<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<DIV style="position:relative;width:931;height:1243;">
<STYLE type="text/css">
<!--
    .ft00{font-size:11px;font-family:Times;color:#ffffff;}
    .ft01{font-size:11px;font-family:Times;color:#ffffff;}
-->
</STYLE>
</HEAD>
</HTML>
  • 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-06-13T18:37:10+00:00Added an answer on June 13, 2026 at 6:37 pm

    If the style is embedded in your Element you just have to use .attr("style").

    JSoup is not a Html renderer, it is just a HTML parser, so you will have to parse the content from the retrieved <style> tag html content. You can use a simple regex for this; but it won’t work in all cases. You may want to use a CSS parser for this task.

    public class Test {
        public static void main(String[] args) throws Exception {
            String html = "<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:931;height:1243;\">\n"+
                    "<STYLE type=\"text/css\">\n"+
                    "<!--\n"+
                    "    .ft00{font-size:11px;font-family:Times;color:#ffffff;}\n"+
                    "    .ft01{font-size:11px;font-family:Times;color:#ffffff;}\n"+
                    "-->\n"+
                    "</STYLE>\n"+
                    "</HEAD>\n"+
                    "</HTML>";
    
            Document doc = Jsoup.parse(html);
            Element style = doc.select("style").first();
            Matcher cssMatcher = Pattern.compile("[.](\\w+)\\s*[{]([^}]+)[}]").matcher(style.html());
            while (cssMatcher.find()) {
                System.out.println("Style `" + cssMatcher.group(1) + "`: " + cssMatcher.group(2));
            }
        }
    }
    

    Will output:

    Style `ft00`: font-size:11px;font-family:Times;color:#ffffff;
    Style `ft01`: font-size:11px;font-family:Times;color:#ffffff;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help me in extracting text from within the html tags to plain
Can anyone help or provide me with some suggestions for the below query. I
Can anyone help me create an android layout like the image below. It has
Can anyone help? I created a DB under APP_Data using ADD ITEM and choosing
Can anyone help me figure this out? The below code works fine and gets
Can anyone help me with finding regular expression for the below $string = id=A12dk9-mds&name=4950;
Can anyone help, I am using the following for adding a bookmark to IE
Can anyone help with a function that will parse all urls into valid html
Can anyone help me for a Java code which copy or move one folder
Can anyone help by providing some samples, or examples to generate a css class

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.