|
|
@@ -0,0 +1,90 @@
|
|
|
+package parser;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.URL;
|
|
|
+import java.nio.charset.Charset;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.logging.Level;
|
|
|
+import java.util.logging.Logger;
|
|
|
+
|
|
|
+import javax.sql.rowset.spi.SyncResolver;
|
|
|
+
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.gargoylesoftware.htmlunit.BrowserVersion;
|
|
|
+import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
|
|
|
+import com.gargoylesoftware.htmlunit.Page;
|
|
|
+import com.gargoylesoftware.htmlunit.WebClient;
|
|
|
+import com.gargoylesoftware.htmlunit.WebResponse;
|
|
|
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
|
|
+
|
|
|
+
|
|
|
+public class ExpektParser {
|
|
|
+
|
|
|
+ public ExpektParser() {
|
|
|
+ getJSON();
|
|
|
+ //getSoccerMatches();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static JsonNode get(URL url) throws Exception {
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ return mapper.readTree(url);
|
|
|
+ }
|
|
|
+
|
|
|
+ // https://eu-offering.kambicdn.org/offering/v2018/expektse/listView/football.json?lang=sv_SE&market=SE
|
|
|
+
|
|
|
+private void getJSON() {
|
|
|
+ try {
|
|
|
+ URL url = new URL("https://eu-offering.kambicdn.org/offering/v2018/expektse/listView/football.json?lang=sv_SE&market=SE");
|
|
|
+ System.out.println("Getting url");
|
|
|
+ JsonNode node = get(url);
|
|
|
+ System.out.println("Got URL");
|
|
|
+ System.out.println(node.elements().next());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+ private void getSoccerMatches() {
|
|
|
+ String url = "https://www.expekt.se/sv-se/sports#filter/football";
|
|
|
+
|
|
|
+ WebClient webClient = new WebClient();
|
|
|
+ webClient.getOptions().setUseInsecureSSL(true);
|
|
|
+ webClient.getOptions().setCssEnabled(false);
|
|
|
+ webClient.getOptions().setJavaScriptEnabled(false);
|
|
|
+ webClient.getOptions().setThrowExceptionOnScriptError(false);
|
|
|
+ Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
|
|
|
+
|
|
|
+ //webClient.waitForBackgroundJavaScript(20000);
|
|
|
+ try {
|
|
|
+ System.out.println("Starting to Get page with wait 20 seconds " + LocalDateTime.now());
|
|
|
+
|
|
|
+ webClient.waitForBackgroundJavaScript(3000);
|
|
|
+ HtmlPage page = webClient.getPage(url);
|
|
|
+
|
|
|
+ page = webClient.getPage(url);
|
|
|
+
|
|
|
+ System.out.println(page.asNormalizedText());
|
|
|
+
|
|
|
+ WebResponse webResponse = page.getWebResponse();
|
|
|
+ int i = 0;
|
|
|
+ // while (!webResponse.getContentAsString().contains("KambiBC-event-groups-list")){
|
|
|
+ // webClient.waitForBackgroundJavaScript(500);
|
|
|
+ // if (i++ < 50) {
|
|
|
+ // System.out.println("Waiting");
|
|
|
+
|
|
|
+ // } else {
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ System.out.println("Done waiting " + LocalDateTime.now());
|
|
|
+
|
|
|
+ //System.out.println(webResponse.getContentAsString());
|
|
|
+ } catch (FailingHttpStatusCodeException | IOException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|