Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Get CSS Attributes using Java

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Get CSS Attributes using Java

    I am trying to access a website using Java and get from it the CSS properties of say a specific div for example. So, I need to know that that div has a width of 500px, background-color red etc etc. It may be because that div has a class, an ID or simply because it is a div. The most important thing is that because of CSS inheritance, I need to know exactly what that div's properties are. To make it clear, I need the final values in a similar way as the attribute properties that appear to the right hand part of Firebug when you do an inspect element of a particular HTML tag. All I need are the final values and properties (not what has been overridden). I first tried to research if there is something that makes Firebug save on a text file and then I analyze it using Java but I think it will get too dependent on what Firebug's features will be in the future so it may be risky. Another idea was to build a tree in Java and put in it CSS of each HTML tag so the lowest node is the final property. Is there any inbuilt function in Java that can get you the actual CSS properties of specific HTML tag ? This would avoid me having to rewrite the wheel Thanks a lot for your kind help!


  2. #2
    Junior Member
    Join Date
    Feb 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Get CSS Attributes using Java

    I am facing the same problem - I need to write a program that could access the website, extract its CSS structure with values and compare it to CSS of another website. Something like Justin said - to have a structure of CSS like a tree (similar to firebug).

    Maybe any ideas how to do that? Any help would be really appreciated...

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Get CSS Attributes using Java

    I guess the first step would be to grab the source of the website. Try this:

    http://www.javaprogrammingforums.com...bsite-url.html

    Once you have the source, you can look for the .css file links within it. Extract the links, then use this to gather the information you need.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Cannot access class attributes
    By Cyburg in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 29th, 2010, 07:30 AM
  2. looping through an ArrayList of objects with their own attributes
    By etidd in forum Java Theory & Questions
    Replies: 2
    Last Post: April 2nd, 2010, 06:15 AM

Tags for this Thread