开发者

How to check in Java color of text when I have .html and .css files?

I have html with css and I want to check what is real color (and other visual text attributes) of specified text开发者_Go百科 in html document. Can I do this with JSoup or must I look for some real-like html engine/processor? Speed of processing this operation is one of main factor.


I think he wants to retreive this data in Java program. So you need few things to do.

  1. Download stylesheet files.
  2. Parse html and find class attribute.
  3. Match .class in css with html attribute and find specific information you want.

But beware if you want to find information about any html element without class attribute. In such case you need to find xpath of html element e.g:

<table class="entityTable">
<tr>
<td> <input type="text" value="abcdef" /></td>
</tr>

Then you need to find xpath like : body/div/.../table/tr/td/input and you need to match any css rules which can influence your input tag attributes.

.entityTable tr td input
{
 color:red;
}

This is much more difficult so if html to parse is your page put everywhere class attribute into your html tags. Otherwise you need to find way to mach html tags to css rules.

Cheers.


Though it is still in beta, the Cobra HTML parser has this capability.


if you need to know accurate info about the object in web page,
like default border of standard HTML table, or color of a standard link,
use FireBug extension for FireFox.


If you're doing this in an applet, you can use javascript to collect the information, and pass it to your applet.


CSSBox is definitely what you want. It allow you to load external css and transform it in inline style for every dom element.

http://cssbox.sourceforge.net/manual/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜