Guest User

Untitled

a guest
Oct 16th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. private static String getOnlyKyrsi(String only) throws Exception{
  2. Pattern pattern = Pattern.compile("([A-Z]){1,}\s([0-9]){1,}\.([0-9]){1,}\s([^-+])") ;
  3. Matcher matcher = pattern.matcher(only);
  4. if(matcher.find()){
  5. return matcher.group();
  6. }
  7. throw new Exception("Ne mogy naiti");
  8. }
  9.  
  10. public static void main( String[] args ) throws Exception{
  11.  
  12. Document doc = (Document) Jsoup.connect("https://kurs.com.ua/gorod/1217-lvov/").get();
  13. Element kursi = doc.select("table[class = ipsTable ipsKursTable ipsKursTable_board ipsKursTable_summary]").first();
  14. Elements body = kursi.select("tbody[data-role= tableRows");
  15. String body1 = kursi.select("tbody[data-role= tableRows").text();
  16. System.out.println(body1);
  17.  
  18. for (Element body2:body){
  19. String others = body2.select("tr[class]").text();
  20. String kursiValut = getOnlyKyrsi(others);
  21. System.out.println(kursiValut);
  22. }
  23.  
  24. Element body = kursi.select("tbody[data-role= tableRows").get(0);
  25. Elements allLines = body.select("tr");
  26. for (Element line : allLines) {
  27. String currency = line.select("td[class = ipsKursTable_currency]").text();
  28. String bidPrice = line.select("td[data-rate-type=bid]").text();
  29. //и так далее для всех нужных аттрибутов
  30. }
  31.  
  32. 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";
  33. for (String val : str.split(" (?=[A-Z]+)")) {
  34. String[] splitVal = val.split(" ");
  35. // Здесь splitVal по индексу 0 будет содержать название валюты,
  36. // а в последующих индексах значения идущие после нее.
  37. }
Add Comment
Please, Sign In to add comment