How to extract data between span tag from web site in android? I am trying with php and android but not getting result can you please help me for that problem.? please Find below the code from where we want to extract data which is highlighted .
Número<br /></span><span class="linha">**3943**</span></td><td valign="top" height="30" width="25%"><span class="TextoFundoBrancoNegrito">
Série<br /></span><span class="linha">**0**</span></td><td valign="top" height="30" width="25%"><span class="TextoFundoBrancoNegrito">
Data de emissão<br /></span><span class="linha">**26/08/2013**</span></td></tr></table><table align="center" width="98%"><tr><td class="TituloAreaRestrita">
I want to store data "3943" , "0" , "26/08/2013" in String
.
You are after a string paser or substring methods... this is fairly standard for any developer. What code are you using currently?
Basically you load the whole html data into a single string and then strip it down to only the conent you need. This can be done with split methods that will split a string into an array or other means... this subject has already been covered multiple times...
You can extract data from HTML using Regular Expressions.
Use the following code to extract data between your span tags:
String value = regexMatch(HTML, "<span class=\"linha\">(.+?)</span>");
Here is the function:
public static String regexMatch(String source, String compilePattern) {
// Compile regex pattern
Pattern regexPattern = pattern.compile(compilePattern);
// Create a matcher against input
Matcher regexMatcher = regexPattern.matcher(source);
// Find first match
if (regexMatcher.find()) {
// Return first group
return RegexMatcher.group(1);
}
// Return empty string if no match
return "";
}