Axel Nordh 3 лет назад
Родитель
Сommit
943916fa1f
4 измененных файлов с 300 добавлено и 238 удалено
  1. 31 19
      Odds/src/mysql/Mysql.java
  2. 5 2
      Odds/src/object/ResultDTO.java
  3. 236 194
      Odds/src/parser/OddsPortal.java
  4. 28 23
      Odds/src/parser/ParserBase.java

+ 31 - 19
Odds/src/mysql/Mysql.java

@@ -10,6 +10,8 @@ import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.eclipse.jetty.util.log.Log;
 
@@ -161,25 +163,31 @@ public class Mysql {
 
             for (ResultDTO resultDTO : resultsToInsert) {
 
-                stat.setInt(1, resultDTO.getHomeTeamId());
-                stat.setInt(2, resultDTO.getAwayTeamId());
-                stat.setInt(3, resultDTO.getHomeScore());
-                stat.setInt(4, resultDTO.getAwayScore());
-                stat.setBoolean(5, resultDTO.isOvertime());
-                stat.setFloat(6, resultDTO.getOdds1());
-                stat.setFloat(7, resultDTO.getOddsX());
-                stat.setFloat(8, resultDTO.getOdds2());
-                stat.setInt(9, resultDTO.getCountryId());
-                stat.setString(10, resultDTO.getGameDate().toString());
-                stat.setString(11, resultDTO.getSeason());
-                stat.setInt(12, resultDTO.getLeagueId());
-                stat.setInt(13, resultDTO.getHomeScore());
-                stat.setInt(14, resultDTO.getAwayScore());
-                stat.setFloat(15, resultDTO.getOdds1());
-                stat.setFloat(16, resultDTO.getOddsX());
-                stat.setFloat(17, resultDTO.getOdds2());
-
-                stat.addBatch();
+                if (resultDTO.getHomeTeamId() < 0 || resultDTO.getAwayTeamId() < 0 || resultDTO.getLeagueId() < 0
+                        || resultDTO.getCountryId() < 0) {
+
+                    Logger.getGlobal().log(Level.WARNING, resultDTO.toString());
+                } else {
+                    stat.setInt(1, resultDTO.getHomeTeamId());
+                    stat.setInt(2, resultDTO.getAwayTeamId());
+                    stat.setInt(3, resultDTO.getHomeScore());
+                    stat.setInt(4, resultDTO.getAwayScore());
+                    stat.setBoolean(5, resultDTO.isOvertime());
+                    stat.setFloat(6, resultDTO.getOdds1());
+                    stat.setFloat(7, resultDTO.getOddsX());
+                    stat.setFloat(8, resultDTO.getOdds2());
+                    stat.setInt(9, resultDTO.getCountryId());
+                    stat.setString(10, resultDTO.getGameDate().toString());
+                    stat.setString(11, resultDTO.getSeason());
+                    stat.setInt(12, resultDTO.getLeagueId());
+                    stat.setInt(13, resultDTO.getHomeScore());
+                    stat.setInt(14, resultDTO.getAwayScore());
+                    stat.setFloat(15, resultDTO.getOdds1());
+                    stat.setFloat(16, resultDTO.getOddsX());
+                    stat.setFloat(17, resultDTO.getOdds2());
+
+                    stat.addBatch();
+                }
             }
 
             stat.executeBatch();
@@ -319,6 +327,10 @@ public class Mysql {
         } catch (SQLException e) {
             e.printStackTrace();
         }
+        if (id == -1) {
+            String message = "Cound not find league " + leagueName + " countryId " + countryId + " sportId " + sportId;
+            Logger.getGlobal().log(Level.WARNING, message);
+        }
         return id;
     }
 

+ 5 - 2
Odds/src/object/ResultDTO.java

@@ -28,6 +28,8 @@ public class ResultDTO {
 
     public ResultDTO(String tableName) {
         super();
+        homeScore = -1;
+        awayScore = -1;
         this.tableName = tableName;
     }
 
@@ -232,7 +234,8 @@ public class ResultDTO {
 
     @Override
     public String toString() {
-        return homeTeam + "," + awayTeam + "," + odds1 + "," + oddsX + "," + odds2 + "," + oddsOver25goals + ","
-                + oddsUnder25goals;
+        return homeTeam + " (" + homeTeamId + "), " + awayTeam + " (" + awayTeamId + "), leagueId " + leagueId
+                + ", countryId " + countryId + ", " + odds1 + "," + oddsX + ","
+                + odds2 + ", score " + homeScore + "-" + awayScore;
     }
 }

+ 236 - 194
Odds/src/parser/OddsPortal.java

@@ -1,29 +1,23 @@
 package parser;
 
-import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
-import java.util.Locale;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import org.eclipse.jetty.util.log.Log;
 import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.chrome.ChromeDriver;
+import org.openqa.selenium.chrome.ChromeOptions;
+import org.openqa.selenium.remote.RemoteWebDriver;
 
-import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
-import com.gargoylesoftware.htmlunit.WebClient;
-import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
-import com.gargoylesoftware.htmlunit.html.HtmlDivision;
-import com.gargoylesoftware.htmlunit.html.HtmlPage;
-import com.gargoylesoftware.htmlunit.html.HtmlSpan;
-import com.gargoylesoftware.htmlunit.html.HtmlTable;
-import com.gargoylesoftware.htmlunit.html.HtmlTableCell;
-import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
 import com.google.common.base.Strings;
 
 import mysql.Mysql;
@@ -33,13 +27,11 @@ public class OddsPortal extends ParserBase implements ParserJoinedFunctions {
 
     private static final String DIV_CONTAINS_CLASS_TABS_DIV_NOT_CLASS_DIV_1_DIV = "//div[contains(@class,'tabs')]/div[not(@class)]/div[1]/div";
     private static final String SOCCER_RESULTS_TABLE_NAME = "SoccerResults";
-    private static final String CLASS = "class";
     private static final String DATE_PATTERN = "yyyyMMdd";
     private LocalDateTime baseDate;
     private int sportId;
     private int countryId;
     private int leagueId;
-    private LocalDateTime gameDate;
 
     final int sportsId = Mysql.getInstance().getSportId("soccer");
     private int currentLeagueId;
@@ -47,82 +39,83 @@ public class OddsPortal extends ParserBase implements ParserJoinedFunctions {
     private List<ResultDTO> resultsToInsert = new ArrayList<>();
     private String currentSeason;
 
-    public void getHistoricMatches(String sport, String country, String league, String year) {
-        final String url = "https://www.oddsportal.com/";
-        final String resultsPage = "/results";
-        final WebClient webClient = new WebClient();
-        webClient.getOptions().setUseInsecureSSL(true);
-        webClient.getOptions().setCssEnabled(false);
-        webClient.getOptions().setJavaScriptEnabled(true);
-        webClient.getOptions().setThrowExceptionOnScriptError(false);
-        Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
-
-        league = league.replace(" ", "-");
-        league = league.replace("\\.", "");
-        country = country.replace(" ", "-");
-        league = league.replace("\\.", "");
-        final Mysql mysql = Mysql.getInstance();
-
-        int currentParsePage = 1;
-
-        final String urlYearPart;
-        if (year.equals(String.valueOf(LocalDate.now().getYear()))) {
-            urlYearPart = "";
-        } else {
-            urlYearPart = "-" + year;
-        }
-
-        try {
-            sportId = mysql.getSportId(sport);
-            countryId = mysql.getCountryId(country);
-            leagueId = mysql.getLeagueId(sportId, countryId, league);
-            String season = "";
-
-            final HtmlPage leaguePage = webClient
-                    .getPage(url + "/" + sport + "/" + country + "/" + league + urlYearPart + resultsPage);
-            final List<HtmlAnchor> yearFilter = leaguePage.getByXPath("//ul[contains(@class,'main-filter')]//a");
-            for (final HtmlAnchor a : yearFilter) {
-                final String active = ((HtmlSpan) a.getParentNode().getParentNode()).getAttribute(CLASS);
-                if (active.contains("active") && !active.contains("inactive")) {
-                    season = a.asNormalizedText();
-                    year = season.replace('/', '-');
-                }
-            }
-
-            HtmlDivision tournamentTableDiv = leaguePage.getHtmlElementById("tournamentTable");
-            HtmlTable tournamentTable = (HtmlTable) tournamentTableDiv.getFirstChild();
-
-            gameDate = LocalDateTime.now();
-            final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd MMM yyyy", Locale.ENGLISH);
-            parseTournamentTable(sportId, countryId, leagueId, season, tournamentTable, gameDate, dateFormatter);
-            final HtmlDivision paginationLinksDiv = (HtmlDivision) tournamentTableDiv.getLastChild();
-            final List<HtmlAnchor> pagiantionLinks = paginationLinksDiv
-                    .getByXPath(".//a[contains(@href, 'page') and not(.//span[contains(@class, 'arrow')])]");
-            for (final HtmlAnchor a : pagiantionLinks) {
-                // When done with start page click pagiantion
-                final int parsePage = Integer.parseInt(a.getTextContent());
-                if (parsePage > currentParsePage) {
-                    a.click();
-                    webClient.waitForBackgroundJavaScript(1000);
-
-                    tournamentTableDiv = leaguePage.getHtmlElementById("tournamentTable");
-                    tournamentTable = (HtmlTable) tournamentTableDiv.getFirstChild();
-                    parseTournamentTable(sportId, countryId, leagueId, season, tournamentTable, gameDate,
-                            dateFormatter);
-                    currentParsePage = parsePage;
-                }
-                // process new tournament table content
-            }
-        } catch (FailingHttpStatusCodeException | IOException e) {
-            e.printStackTrace();
-        } catch (final ClassCastException cce) {
-            Log.getLog().info("Class cast exception message: " + cce.getMessage() + " \ncause: " + cce.getCause());
-        } finally {
-            Mysql.getInstance().setParsingForLeague(leagueId, sportId, countryId, gameDate, currentParsePage, year);
-        }
-        webClient.close();
-        Log.getLog().info("DONE with " + country + " (" + countryId + ") league " + league + "(" + leagueId + ")");
-    }
+//    Behöver göras om till selenium
+//    public void getHistoricMatches(String sport, String country, String league, String year) {
+//        final String url = "https://www.oddsportal.com/";
+//        final String resultsPage = "/results";
+//        final WebClient webClient = new WebClient();
+//        webClient.getOptions().setUseInsecureSSL(true);
+//        webClient.getOptions().setCssEnabled(false);
+//        webClient.getOptions().setJavaScriptEnabled(true);
+//        webClient.getOptions().setThrowExceptionOnScriptError(false);
+//        Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
+//
+//        league = league.replace(" ", "-");
+//        league = league.replace("\\.", "");
+//        country = country.replace(" ", "-");
+//        league = league.replace("\\.", "");
+//        final Mysql mysql = Mysql.getInstance();
+//
+//        int currentParsePage = 1;
+//
+//        final String urlYearPart;
+//        if (year.equals(String.valueOf(LocalDate.now().getYear()))) {
+//            urlYearPart = "";
+//        } else {
+//            urlYearPart = "-" + year;
+//        }
+//
+//        try {
+//            sportId = mysql.getSportId(sport);
+//            countryId = mysql.getCountryId(country);
+//            leagueId = mysql.getLeagueId(sportId, countryId, league);
+//            String season = "";
+//
+//            final HtmlPage leaguePage = webClient
+//                    .getPage(url + "/" + sport + "/" + country + "/" + league + urlYearPart + resultsPage);
+//            final List<HtmlAnchor> yearFilter = leaguePage.getByXPath("//ul[contains(@class,'main-filter')]//a");
+//            for (final HtmlAnchor a : yearFilter) {
+//                final String active = ((HtmlSpan) a.getParentNode().getParentNode()).getAttribute(CLASS);
+//                if (active.contains("active") && !active.contains("inactive")) {
+//                    season = a.asNormalizedText();
+//                    year = season.replace('/', '-');
+//                }
+//            }
+//
+//            HtmlDivision tournamentTableDiv = leaguePage.getHtmlElementById("tournamentTable");
+//            HtmlTable tournamentTable = (HtmlTable) tournamentTableDiv.getFirstChild();
+//
+//            gameDate = LocalDateTime.now();
+//            final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd MMM yyyy", Locale.ENGLISH);
+//            parseTournamentTable(sportId, countryId, leagueId, season, tournamentTable, gameDate, dateFormatter);
+//            final HtmlDivision paginationLinksDiv = (HtmlDivision) tournamentTableDiv.getLastChild();
+//            final List<HtmlAnchor> pagiantionLinks = paginationLinksDiv
+//                    .getByXPath(".//a[contains(@href, 'page') and not(.//span[contains(@class, 'arrow')])]");
+//            for (final HtmlAnchor a : pagiantionLinks) {
+//                // When done with start page click pagiantion
+//                final int parsePage = Integer.parseInt(a.getTextContent());
+//                if (parsePage > currentParsePage) {
+//                    a.click();
+//                    webClient.waitForBackgroundJavaScript(1000);
+//
+//                    tournamentTableDiv = leaguePage.getHtmlElementById("tournamentTable");
+//                    tournamentTable = (HtmlTable) tournamentTableDiv.getFirstChild();
+//                    parseTournamentTable(sportId, countryId, leagueId, season, tournamentTable, gameDate,
+//                            dateFormatter);
+//                    currentParsePage = parsePage;
+//                }
+//                // process new tournament table content
+//            }
+//        } catch (FailingHttpStatusCodeException | IOException e) {
+//            e.printStackTrace();
+//        } catch (final ClassCastException cce) {
+//            Log.getLog().info("Class cast exception message: " + cce.getMessage() + " \ncause: " + cce.getCause());
+//        } finally {
+//            Mysql.getInstance().setParsingForLeague(leagueId, sportId, countryId, gameDate, currentParsePage, year);
+//        }
+//        webClient.close();
+//        Log.getLog().info("DONE with " + country + " (" + countryId + ") league " + league + "(" + leagueId + ")");
+//    }
 
     public void getNextDaysMatches() {
         baseDate = LocalDateTime.now().plusDays(2);
@@ -183,25 +176,62 @@ public class OddsPortal extends ParserBase implements ParserJoinedFunctions {
 
     private void getMatchesByDateSelenium(String date) {
         final String soccerUrl = "https://oddsportal.com/matches/soccer/" + date;
-        parseSoccerMatchesSelenium(soccerUrl);
+        try {
+            parseSoccerMatchesSelenium(soccerUrl);
+        } catch (MalformedURLException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
     }
 
-    private void parseSoccerMatchesSelenium(final String soccerUrl) {
-        ChromeDriver driver = getSeleniumDriver();
+    private void parseSoccerMatchesSelenium(final String soccerUrl) throws MalformedURLException {
+        // ChromeDriver driver = getSeleniumDriver();
+//        DesiredCapabilities capabilities = new DesiredCapabilities();
+//        capabilities.setCapability("browserName", "Chrome");
+//        capabilities.setPlatform(Platform.LINUX);
+
+        ChromeOptions options = new ChromeOptions();
+        // Fixing 255 Error crashes
+        options.addArguments("--no-sandbox");
+        options.addArguments("--disable-dev-shm-usage");
+
+        // Options to trick bot detection
+        // Removing webdriver property
+        options.addArguments("--disable-blink-features=AutomationControlled");
+        options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
+        options.setExperimentalOption("useAutomationExtension", null);
+
+        // Changing the user agent / browser fingerprint
+        options.addArguments("window-size=1920,1080");
+        options.addArguments(
+                "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
+
+        // Other
+        options.addArguments("disable-infobars");
+
+        WebDriver driver = new RemoteWebDriver(new URL("http://nordh.xyz:4444/wd/hub"), options);
         sportId = Mysql.getInstance().getSportId("soccer");
         driver.get(soccerUrl);
 
         try {
-            Thread.sleep(400);
+            Thread.sleep(1500);
 
-            List<WebElement> divs = driver
-                    .findElements(By.xpath(DIV_CONTAINS_CLASS_TABS_DIV_NOT_CLASS_DIV_1_DIV));
+            if (!checkIfElementExists(driver, "//p[text()='EU Odds']")) {
+                WebElement oddsFormat = driver
+                        .findElement(By.xpath("//p[@class='self-center text-xs text-orange-main'][1]"));
 
-            int divsCount = divs.size();
+                oddsFormat.click();
 
-            divs = scrollAndGetAllMatchDivs(driver, divs, divsCount);
+                driver.findElement(By.xpath("//a[text()='EU Odds']")).click();
+                Thread.sleep(2000);
+            }
+
+            List<WebElement> divs = driver
+                    .findElements(By.xpath(DIV_CONTAINS_CLASS_TABS_DIV_NOT_CLASS_DIV_1_DIV));
 
-            for (WebElement element : divs) {
+            for (int i = 0; i < divs.size(); i++) {
+                WebElement element = divs.get(i);
+                scrollElementIntoView(driver, element);
                 ResultDTO result = new ResultDTO(SOCCER_RESULTS_TABLE_NAME);
 
                 boolean somethingWrong = false;
@@ -255,7 +285,8 @@ public class OddsPortal extends ParserBase implements ParserJoinedFunctions {
                     }
 
                 }
-
+                divs = driver
+                        .findElements(By.xpath(DIV_CONTAINS_CLASS_TABS_DIV_NOT_CLASS_DIV_1_DIV));
             }
         } catch (InterruptedException e) {
             e.printStackTrace();
@@ -266,106 +297,117 @@ public class OddsPortal extends ParserBase implements ParserJoinedFunctions {
         Logger.getGlobal().log(Level.INFO, message);
         Mysql.getInstance().addResults(resultsToInsert);
         resultsToInsert.clear();
-        driver.close();
+//        driver.close();
+        driver.quit();
     }
 
-    private void parseTournamentTable(int sportId, int countryId, int leagueId, String season,
-            HtmlTable tournamentTable, LocalDateTime gameDate,
-            DateTimeFormatter dateFormatter) {
-        for (final HtmlTableRow tr : tournamentTable.getRows()) {
-            if (tr.getAttribute(CLASS).contains("deactivate")) {
-                String homeTeam;
-                String awayTeam;
-                int homeScore = -1;
-                int awayScore = -1;
-                float odds1 = 0f;
-                float oddsX = 0f;
-                float odds2 = 0f;
-                boolean overtime = false;
-
-                final HtmlTableCell timeCell = tr.getCell(0);
-                final HtmlTableCell participantsCell = tr.getCell(1);
-
-                // Game Time
-                final String[] timeValue = timeCell.asNormalizedText().split(":");
-                if (gameDate != null) {
-                    gameDate = gameDate.withHour(Integer.valueOf(timeValue[0]));
-                    gameDate = gameDate.withMinute(Integer.valueOf(timeValue[1]));
-                }
-
-                // Teams
-                final String[] participantsValue = participantsCell.asNormalizedText().split(" - ");
-                homeTeam = participantsValue[0].trim();
-                awayTeam = participantsValue[1].trim();
-
-                final List<HtmlTableCell> cells = tr.getCells();
-                for (final HtmlTableCell tc : cells) {
-                    // Score
-                    if (tc.getAttribute(CLASS).contains("table-score")) {
-                        final String[] scoreValue = tc.asNormalizedText().split(":");
-                        if (scoreValue[0].matches("\\D+")) {
-                            continue;
-                        }
-                        homeScore = Integer.valueOf(scoreValue[0]);
-                        if (scoreValue[1].matches("\\D+")) {
-                            overtime = true;
-                        }
-                        awayScore = Integer.valueOf(scoreValue[1].replaceAll("\\D+", ""));
-                    }
-
-                    if (tc.getAttribute(CLASS).contains("odds-nowrp")) {
-                        if (tc.asNormalizedText().matches("[+-][0-9][0-9][0-9]")) {
-                            if (odds1 == 0F) {
-                                odds1 = convertAmericanOddsToDecimal(Integer.valueOf(tc.asNormalizedText()));
-                            } else if (oddsX == 0F) {
-                                oddsX = convertAmericanOddsToDecimal(Integer.valueOf(tc.asNormalizedText()));
-                            } else if (odds2 == 0F) {
-                                odds2 = convertAmericanOddsToDecimal(Integer.valueOf(tc.asNormalizedText()));
-                            }
-                        } else if (tc.asNormalizedText().matches("[0-9]+.[0-9]+")) {
-                            if (odds1 == 0F) {
-                                odds1 = Float.valueOf(tc.asNormalizedText());
-                            } else if (oddsX == 0F) {
-                                oddsX = Float.valueOf(tc.asNormalizedText());
-                            } else if (odds2 == 0F) {
-                                odds2 = Float.valueOf(tc.asNormalizedText());
-                            }
-                        }
-                    }
-                }
-
-                if (gameDate != null && homeTeam != null && awayTeam != null && odds1 != 0 && oddsX != 0 && odds2 != 0
-                        && !Strings.isNullOrEmpty(season)) { // All set.. update sql result table
-                    Mysql.getInstance()
-                            .addResult(new ResultDTO(SOCCER_RESULTS_TABLE_NAME, gameDate, homeTeam, awayTeam, homeScore,
-                                    awayScore, overtime, odds1,
-                                    oddsX, odds2, countryId, season, leagueId, sportId));
-                } else {
-                    Log.getLog()
-                            .info(String.format("Failed to insert result %s %s %s odds %s %s %s season %s", gameDate,
-                                    homeTeam, awayTeam, odds1,
-                                    oddsX, odds2, season));
-                }
-
-            } else if (tr.getAttribute(CLASS).contains("center nob-border")) { // Datum rader
-                final List<HtmlSpan> dateSpan = tr.getByXPath(".//span[contains(@class, 'datet')]");
-                final String dateString = dateSpan.get(0).asNormalizedText();
-                if (dateString.toLowerCase().contains("yesterday")) {
-                    gameDate = LocalDateTime.now().minusDays(1);
-                } else if (dateString.toLowerCase().contains("today")) {
-                    gameDate = LocalDateTime.now();
-                } else {
-                    gameDate = LocalDate.parse(dateString, dateFormatter).atStartOfDay();
-                }
-            }
-        }
-    }
+    /*
+     * Behöver göras om till Selenium
+     * private void parseTournamentTable(int sportId, int countryId, int leagueId,
+     * String season,
+     * HtmlTable tournamentTable, LocalDateTime gameDate,
+     * DateTimeFormatter dateFormatter) {
+     * for (final HtmlTableRow tr : tournamentTable.getRows()) {
+     * if (tr.getAttribute(CLASS).contains("deactivate")) {
+     * String homeTeam;
+     * String awayTeam;
+     * int homeScore = -1;
+     * int awayScore = -1;
+     * float odds1 = 0f;
+     * float oddsX = 0f;
+     * float odds2 = 0f;
+     * boolean overtime = false;
+     *
+     * final HtmlTableCell timeCell = tr.getCell(0);
+     * final HtmlTableCell participantsCell = tr.getCell(1);
+     *
+     * // Game Time
+     * final String[] timeValue = timeCell.asNormalizedText().split(":");
+     * if (gameDate != null) {
+     * gameDate = gameDate.withHour(Integer.valueOf(timeValue[0]));
+     * gameDate = gameDate.withMinute(Integer.valueOf(timeValue[1]));
+     * }
+     *
+     * // Teams
+     * final String[] participantsValue =
+     * participantsCell.asNormalizedText().split(" - ");
+     * homeTeam = participantsValue[0].trim();
+     * awayTeam = participantsValue[1].trim();
+     *
+     * final List<HtmlTableCell> cells = tr.getCells();
+     * for (final HtmlTableCell tc : cells) {
+     * // Score
+     * if (tc.getAttribute(CLASS).contains("table-score")) {
+     * final String[] scoreValue = tc.asNormalizedText().split(":");
+     * if (scoreValue[0].matches("\\D+")) {
+     * continue;
+     * }
+     * homeScore = Integer.valueOf(scoreValue[0]);
+     * if (scoreValue[1].matches("\\D+")) {
+     * overtime = true;
+     * }
+     * awayScore = Integer.valueOf(scoreValue[1].replaceAll("\\D+", ""));
+     * }
+     *
+     * if (tc.getAttribute(CLASS).contains("odds-nowrp")) {
+     * if (tc.asNormalizedText().matches("[+-][0-9][0-9][0-9]")) {
+     * if (odds1 == 0F) {
+     * odds1 = convertAmericanOddsToDecimal(Integer.valueOf(tc.asNormalizedText()));
+     * } else if (oddsX == 0F) {
+     * oddsX = convertAmericanOddsToDecimal(Integer.valueOf(tc.asNormalizedText()));
+     * } else if (odds2 == 0F) {
+     * odds2 = convertAmericanOddsToDecimal(Integer.valueOf(tc.asNormalizedText()));
+     * }
+     * } else if (tc.asNormalizedText().matches("[0-9]+.[0-9]+")) {
+     * if (odds1 == 0F) {
+     * odds1 = Float.valueOf(tc.asNormalizedText());
+     * } else if (oddsX == 0F) {
+     * oddsX = Float.valueOf(tc.asNormalizedText());
+     * } else if (odds2 == 0F) {
+     * odds2 = Float.valueOf(tc.asNormalizedText());
+     * }
+     * }
+     * }
+     * }
+     *
+     * if (gameDate != null && homeTeam != null && awayTeam != null && odds1 != 0 &&
+     * oddsX != 0 && odds2 != 0
+     * && !Strings.isNullOrEmpty(season)) { // All set.. update sql result table
+     * Mysql.getInstance()
+     * .addResult(new ResultDTO(SOCCER_RESULTS_TABLE_NAME, gameDate, homeTeam,
+     * awayTeam, homeScore,
+     * awayScore, overtime, odds1,
+     * oddsX, odds2, countryId, season, leagueId, sportId));
+     * } else {
+     * Log.getLog()
+     * .info(String.
+     * format("Failed to insert result %s %s %s odds %s %s %s season %s", gameDate,
+     * homeTeam, awayTeam, odds1,
+     * oddsX, odds2, season));
+     * }
+     *
+     * } else if (tr.getAttribute(CLASS).contains("center nob-border")) { // Datum
+     * rader
+     * final List<HtmlSpan> dateSpan =
+     * tr.getByXPath(".//span[contains(@class, 'datet')]");
+     * final String dateString = dateSpan.get(0).asNormalizedText();
+     * if (dateString.toLowerCase().contains("yesterday")) {
+     * gameDate = LocalDateTime.now().minusDays(1);
+     * } else if (dateString.toLowerCase().contains("today")) {
+     * gameDate = LocalDateTime.now();
+     * } else {
+     * gameDate = LocalDate.parse(dateString, dateFormatter).atStartOfDay();
+     * }
+     * }
+     * }
+     * }
+     */
 
     private List<WebElement> scrollAndGetAllMatchDivs(ChromeDriver driver, List<WebElement> divs, int divsCount)
             throws InterruptedException {
         if (divsCount > 0) {
             scrollElementIntoViewCenter(driver, divs.get(divsCount - 1));
-            Thread.sleep(1000);
+            Thread.sleep(2000);
             divs = driver
                     .findElements(By.xpath(DIV_CONTAINS_CLASS_TABS_DIV_NOT_CLASS_DIV_1_DIV));
         }
@@ -374,7 +416,7 @@ public class OddsPortal extends ParserBase implements ParserJoinedFunctions {
             if (divsCount > 0) {
                 divsCount = divs.size();
                 scrollElementIntoViewCenter(driver, divs.get(divsCount - 1));
-                Thread.sleep(1000);
+                Thread.sleep(2000);
                 divs = driver
                         .findElements(By.xpath(DIV_CONTAINS_CLASS_TABS_DIV_NOT_CLASS_DIV_1_DIV));
             }

+ 28 - 23
Odds/src/parser/ParserBase.java

@@ -5,6 +5,7 @@ import java.util.Collections;
 
 import org.openqa.selenium.By;
 import org.openqa.selenium.JavascriptExecutor;
+import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.chrome.ChromeDriver;
 import org.openqa.selenium.chrome.ChromeOptions;
@@ -12,6 +13,29 @@ import org.openqa.selenium.support.ui.WebDriverWait;
 
 public class ParserBase {
 
+    protected boolean checkIfElementExists(WebDriver driver, String xpath) {
+        return !driver.findElements(By.xpath(xpath)).isEmpty();
+    }
+
+    protected boolean checkIfElementExists(WebElement element, String xpath) {
+        return !element.findElements(By.xpath(xpath)).isEmpty();
+    }
+
+    protected float formatFloat(String string) {
+        float result = -1f;
+        try {
+            result = Float.parseFloat(string);
+        } catch (NumberFormatException e) {
+            // Empty by design
+        }
+
+        return result;
+    }
+
+    protected JavascriptExecutor getJsExecutor(ChromeDriver driver) {
+        return driver;
+    }
+
     protected ChromeDriver getSeleniumDriver() {
         ChromeOptions options = new ChromeOptions();
 
@@ -45,20 +69,7 @@ public class ParserBase {
         return new WebDriverWait(driver, Duration.ofSeconds(30));
     }
 
-    protected JavascriptExecutor getJsExecutor(ChromeDriver driver) {
-        return driver;
-    }
-
-    protected boolean checkIfElementExists(WebElement element, String xpath) {
-        return !element.findElements(By.xpath(xpath)).isEmpty();
-    }
-
-    protected void scrollToTopOfPage(ChromeDriver driver) {
-        ((JavascriptExecutor) driver)
-                .executeScript("document.body.scrollTop = document.documentElement.scrollTop = 0;");
-    }
-
-    protected void scrollElementIntoView(ChromeDriver driver, WebElement element) {
+    protected void scrollElementIntoView(WebDriver driver, WebElement element) {
         ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", element);
     }
 
@@ -66,14 +77,8 @@ public class ParserBase {
         ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView({ block: 'center' });", element);
     }
 
-    protected float formatFloat(String string) {
-        float result = -1f;
-        try {
-            result = Float.parseFloat(string);
-        } catch (NumberFormatException e) {
-            // Empty by design
-        }
-
-        return result;
+    protected void scrollToTopOfPage(ChromeDriver driver) {
+        ((JavascriptExecutor) driver)
+                .executeScript("document.body.scrollTop = document.documentElement.scrollTop = 0;");
     }
 }