This commit is contained in:
2026-05-31 13:36:33 +05:00
parent 19f6475573
commit 94d47092af
7 changed files with 208 additions and 0 deletions

25
CurrencyParser.java Normal file
View File

@@ -0,0 +1,25 @@
import java.util.regex.*;
public class CurrencyParser {
public static double parseUSD(String html) {
Pattern pattern = Pattern.compile(
"<td>USD</td>\\s*" +
"<td>1</td>\\s*" +
"<td>Доллар США</td>\\s*" +
"<td>([0-9,]+)</td>",
Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(html);
if (matcher.find()) {
String rateStr = matcher.group(1).replace(',', '.');
try {
return Double.parseDouble(rateStr);
} catch (NumberFormatException e) {
System.err.println("Ошибка парсинга числа: " + matcher.group(1));
}
}
return -1;
}
}