Web utilization and data processing in java

I am writing a web-clip program to extract stock quotes from yahoo finance, google finance or nasdaq. I can get an html element containing stock prices, but I only need the dollar value from the result. For example, the sample output is as follows: enter image description here

I use the image here because when I posted the actual html, only dollar amounts appeared (desired results), the objects and html tags disappeared. Here is my code   enter image description here  I am not very familiar with regEx, but I tried, but no luck. How can I extract only the dollar amount from the issue?

+4
source share
2 answers

Try using java.util.regex.Matcherand java.util.regex.Pattern:

String pattern = "<td>\\$&.+;(\\d{1,4}\\.\\d{2})&";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(inputLine);

if (m.find( )) {
     System.out.println("Price: $" + m.group(1) );
}

Result:

: $130,27...

:

http://ideone.com/fWgvL5#stdout

+2

str_replace .

$string = str_replace('&nbsp;</td><td>.*?</td>','&nbsp;</td>', $string);

.*? , &nbsp; . . .*? or .*(?) ..

<td>number</td>, <td>$&nbsp;number&nbsp;</td>

, ? - XML-?

0

All Articles