Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.URL;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Main {
- public static void main(String[] args) throws IOException {
- URL url = new URL("http://plk.pl/terminarz-i-wyniki.html");
- String line="";
- Map<String, Team> teams = new HashMap<>();
- BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
- Pattern hostPattern = Pattern.compile("span itemprop=\"homeTeam\"[^>]*>(?:<.*>)*([^<]*)<.*$");
- Pattern guestPattern = Pattern.compile("span itemprop=\"awayTeam\"[^>]*>(?:<.*>)*([^<]*)<.*$");
- Pattern datePattern = Pattern.compile("div class=\"below-sm\"[^>]*>(?:<.*>)*([^<]*)<.*$");
- Pattern pointsPattern = Pattern.compile("(.*(?:\\d{1,3}|--):(?:\\d{1,3}|--).*)</a>$");
- String host = "",guest = "",date = "",score="";
- while ((line = in.readLine()) != null)
- {
- Matcher m = hostPattern.matcher(line);
- while(m.find()){
- host = m.group(1);
- }
- m = guestPattern.matcher(line);
- while(m.find())
- guest = m.group(1);
- m = datePattern.matcher(line);
- while(m.find())
- date = m.group(1);
- m = pointsPattern.matcher(line);
- while(m.find()) {
- score = m.group(1);
- score = score.trim();
- if (!teams.containsKey(host))
- teams.put(host,new Team(host));
- if (!teams.containsKey(guest))
- teams.put(guest,new Team(guest));
- teams.get(host).getHomeMatches().add(new Match(host, guest, date, score));
- teams.get(guest).getAwayMatches().add(new Match(guest, host, date, score));
- }
- }
- in.close();
- System.out.println("Podaj nazwę drużyny:");
- Scanner s = new Scanner(System.in);
- Team team = teams.get(s.nextLine());
- System.out.println("1 --- mecze gospodarskie");
- System.out.println("2 --- mecze wyjazdowe");
- s = new Scanner(System.in);
- if (s.nextInt() == 1)
- System.out.println(team.getHomeMatches());
- else if (s.nextInt() == 2)
- System.out.println(team.getAwayMatches());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement