I am trying to create a program that uses regular expression to scrape data from a website and then display it.
I've been trying for a while to figure out what's going on, but i can't.
I am getting this error on those 3 lines: m cannot be resolved
while (m.find()) {
String stateURL = m.group(1);
String stateName = m.group(2);
public class VisualizaActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.visualiza);
/* Imprime na tela
TextView tv = new TextView(this);
tv.setText(stateName + "," + stateURL);
setContentView(tv); */
}
String expr = "<td><span\\s+class=\"flagicon\"[^>]*>";
public static CharSequence getURLContent(URL url) throws IOException {
URLConnection conn = url.openConnection();
String enconding = conn.getContentEncoding();
if (enconding == null){
enconding = "ISO-8859-1";
}
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), enconding));
StringBuilder sb = new StringBuilder(16384);
try{
String line;
while ((line = br.readLine()) != null){
sb.append(line);
sb.append('\n');
}
} finally{
br.close();
}
return sb;
}
public void x()
{
Pattern patt = Pattern.compile(expr,Pattern.DOTALL | Pattern.UNIX_LINES);
try
{
URL url = new URL("http://en.wikipedia.org/wiki/Mexico");
Matcher m = patt.matcher(getURLContent(url));
}
finally
{
}
while (m.find()) {
String stateURL = m.group(1);
String stateName = m.group(2);
System.out.println(stateName + "," + stateURL);
}
}
}