Sunday, 8 September 2013

How to extract color from span which is in p tag from an html using JSOUP?

How to extract color from span which is in p tag from an html using JSOUP?

<p>My mother has
<span style="color:blue;font-weight:bold">blue</span>
eyes and my father has
<span style="color:darkolivegreen;font-weight:bold">
dark green</span>
eyes.</p>
"My mother has blue eyes and my father has dark green eyes". I want to
parse this sentance using JSOUP and print the same with bold and coloured
text on an android textview. Here "blue" is bold and in blue color. "Dark
Green" is bold and in color.
Elements eHeadder = doc.select("*");
for (Element eHead : eHeadder) {
String tag = eHead.tagName();
if (tag.equals("p")) {
String pText = eHead.text();
tv.setText(pText);
}
}
Above is what I do to get the data in "p" tag. But I need to get span from
the selected "p" tag also need to extract bold and color of the span. I am
using if else ladder here to print the data if tag is "p" else if tag is
"h2" print its data and so on.
Can anybody help me with a solution?
I am confused in using doc.select("p") and doc.select("p").first; Could
you explain this also when you give a reply?

No comments:

Post a Comment