I’m trying to do something similar to: Jsoup: How to get all html between 2 header tags
However, it seems my code is avoiding plain text.
The site I’m parsing has code setup in such a way:
div class = "quoted-message"
Response. Can contain images, text, etc.
div class = "quoted-message"
Another response to another quoted message
Code Snippet used to handle the actual messages:
Element quote = msg.select(".quoted-message").first();
Boolean hasQuote = false;
Elements siblings = null;
siblings = quote.siblingElements();
createQuotePost(quote);
List<Element> elementsBetween = new ArrayList<Element>();
for (int i = 1; i < siblings.size(); i++) {
Element sibling = siblings.get(i);
if (! "div.quoted-message".equals(sibling.tagName())) {
elementsBetween.add(sibling);
}
else {
Log.v("location", "Clear and Process");
processElementsBetween(elementsBetween);
elementsBetween.clear();
}
}
if (! elementsBetween.isEmpty())
processElementsBetween(elementsBetween);
This, however, does not seem to work as I want it to. The responses to the code do not have any special formatting to them (ie: sitting in a p tag). Using a bit of logging, I can see they aren’t getting put into Elements siblings.
Siblings seems to just include line breaks and such.
Note: I’ve only tested this on small posts (simple one liners) to save on sifting through long pages of printouts.
Any suggestions on what to do?
EDIT:
Here is the HTML code snippet between 2 quoted-message divs:
MESSAGE TO BE QUOTED
</div>
<br />
<br />
Hello quoted message
<br />
I am a response
<br />
<br />
<div class="quoted-message">
Think one of the problems is you’re asking for Elements and not Nodes. Text nodes are Nodes and not Elements.
Try this: