Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static String getOnlyKyrsi(String only) throws Exception{
- Pattern pattern = Pattern.compile("([A-Z]){1,}\s([0-9]){1,}\.([0-9]){1,}\s([^-+])") ;
- Matcher matcher = pattern.matcher(only);
- if(matcher.find()){
- return matcher.group();
- }
- throw new Exception("Ne mogy naiti");
- }
- public static void main( String[] args ) throws Exception{
- Document doc = (Document) Jsoup.connect("https://kurs.com.ua/gorod/1217-lvov/").get();
- Element kursi = doc.select("table[class = ipsTable ipsKursTable ipsKursTable_board ipsKursTable_summary]").first();
- Elements body = kursi.select("tbody[data-role= tableRows");
- String body1 = kursi.select("tbody[data-role= tableRows").text();
- System.out.println(body1);
- for (Element body2:body){
- String others = body2.select("tr[class]").text();
- String kursiValut = getOnlyKyrsi(others);
- System.out.println(kursiValut);
- }
- Element body = kursi.select("tbody[data-role= tableRows").get(0);
- Elements allLines = body.select("tr");
- for (Element line : allLines) {
- String currency = line.select("td[class = ipsKursTable_currency]").text();
- String bidPrice = line.select("td[data-rate-type=bid]").text();
- //и так далее для всех нужных аттрибутов
- }
- String str = "USD 27.827 28.161 -0.040 -0.040 28.0035 28.004 -0.046 -0.046 28.002897 28.003 -0.079 -0.079 EUR 31.932 +0.083 +0.083 32.595 +0.085 +0.085 32.3723 32.372 +0.065 +0.065 32.203332 32.203 +0.092 +0.092";
- for (String val : str.split(" (?=[A-Z]+)")) {
- String[] splitVal = val.split(" ");
- // Здесь splitVal по индексу 0 будет содержать название валюты,
- // а в последующих индексах значения идущие после нее.
- }
Add Comment
Please, Sign In to add comment