I want to parse an HTML document and extract a certain div block that can be repeated.
I've managed to extract THE FIRST occurrence of the block, but I cant figure out how to get the next.
This is my code so far:
String inputStr = HTTPGetter.get("http://someurl");
String patternStr ="<div class=\"MY-CLASS\">(.*?)</div>";
// Compile and use regular expression
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(inputStr);
boolean matchFound = matcher.find();
if (matchFound) {
// Get all groups for this match
for (int i=0; i<=matcher.groupCount(); i++) {
String groupStr = matcher.group(i);
System.out.println("Group found:\n"+groupStr);
}
} else {
System.out.println("Not found");
}
The document I'm parsing has more than one div block of class MY-CLASS. I want to get all of them.
How can I do that?