Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.URL;
  3. import java.util.*;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class Main {
  8.  
  9. public static void main(String[] args) throws IOException {
  10. URL url = new URL("http://plk.pl/terminarz-i-wyniki.html");
  11. String line="";
  12.  
  13. Map<String, Team> teams = new HashMap<>();
  14.  
  15. BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
  16. Pattern hostPattern = Pattern.compile("span itemprop=\"homeTeam\"[^>]*>(?:<.*>)*([^<]*)<.*$");
  17. Pattern guestPattern = Pattern.compile("span itemprop=\"awayTeam\"[^>]*>(?:<.*>)*([^<]*)<.*$");
  18. Pattern datePattern = Pattern.compile("div class=\"below-sm\"[^>]*>(?:<.*>)*([^<]*)<.*$");
  19. Pattern pointsPattern = Pattern.compile("(.*(?:\\d{1,3}|--):(?:\\d{1,3}|--).*)</a>$");
  20.  
  21.  
  22. String host = "",guest = "",date = "",score="";
  23. while ((line = in.readLine()) != null)
  24. {
  25. Matcher m = hostPattern.matcher(line);
  26. while(m.find()){
  27. host = m.group(1);
  28. }
  29. m = guestPattern.matcher(line);
  30. while(m.find())
  31. guest = m.group(1);
  32.  
  33. m = datePattern.matcher(line);
  34. while(m.find())
  35. date = m.group(1);
  36.  
  37. m = pointsPattern.matcher(line);
  38. while(m.find()) {
  39. score = m.group(1);
  40. score = score.trim();
  41. if (!teams.containsKey(host))
  42. teams.put(host,new Team(host));
  43.  
  44. if (!teams.containsKey(guest))
  45. teams.put(guest,new Team(guest));
  46.  
  47. teams.get(host).getHomeMatches().add(new Match(host, guest, date, score));
  48. teams.get(guest).getAwayMatches().add(new Match(guest, host, date, score));
  49. }
  50.  
  51.  
  52. }
  53. in.close();
  54.  
  55. System.out.println("Podaj nazwę drużyny:");
  56. Scanner s = new Scanner(System.in);
  57. Team team = teams.get(s.nextLine());
  58.  
  59. System.out.println("1 --- mecze gospodarskie");
  60. System.out.println("2 --- mecze wyjazdowe");
  61. s = new Scanner(System.in);
  62.  
  63. if (s.nextInt() == 1)
  64. System.out.println(team.getHomeMatches());
  65. else if (s.nextInt() == 2)
  66. System.out.println(team.getAwayMatches());
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement