I need to extract some data from an website and then save some values in variables.
Here you've got the code:
public class Principal {
public static void main(String[] args) throws IOException {
URL url = new URL("http://www.numbeo.com/cost-of-living/country_result.jsp?country=Turkey");
URLConnection yc = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
String valor;
String str = null;
while ((inputLine = in.readLine()) != null) {
if(inputLine.contains("Milk"))
{
System.out.println("Encontrei! " + inputLine );
valor=inputLine.substring(inputLine.lastIndexOf("\"priceValue\">") + 14);
System.out.println("valor:" +valor);
}
}
in.close();
}
}
First inputline print this: <tr class="tr_standard"><td>Milk (regular), (1 liter) </td> <td style="text-align: right" class="priceValue"> 2.45 TL</td>
Now I've got to extract just the "2.45"
how can I do that? I already tried with some Regex but can't make it work.
Sorry for my English.
Thanks in advance.