Skip to content

Instantly share code, notes, and snippets.

@andxbes
Created August 8, 2021 14:20
Show Gist options
  • Select an option

  • Save andxbes/914c3c667ea72fe4de6aaae891b5d5d7 to your computer and use it in GitHub Desktop.

Select an option

Save andxbes/914c3c667ea72fe4de6aaae891b5d5d7 to your computer and use it in GitHub Desktop.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package GBet365;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
/**
*
* @author andxbes
*/
public class Main {
static String cookie_aps03 = null;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
// TODO code application logic here
String siteUrl = "https://www.bet365.com";
String config_path = getConfigUrl(siteUrl);
System.out.println(config_path);
String token = getToken(config_path, siteUrl);
System.out.println(token);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
protected static String getToken(String config_path, String siteUrl) throws IOException {
String token = null;
if (config_path != null && !config_path.isEmpty()) {
Document config_doc = Jsoup.connect(siteUrl + config_path)
.cookie("aps03", cookie_aps03)
.ignoreContentType(true)//Для данной либы, она ждет html, а приходит json
.get();
String config_text = config_doc.text();
//System.out.println(config_text);
Pattern pattern_2 = Pattern.compile(",\"SESSION_ID\":\"([^\"]+?)\",");
Matcher matcher_2 = pattern_2.matcher(config_text);
while (matcher_2.find()) {
token = matcher_2.group(1).toString();
break;
}
}
return token;
}
protected static String getConfigUrl(String siteUrl) throws IOException {
Response res1 = Jsoup.connect(siteUrl).execute();
cookie_aps03 = res1.cookie("aps03"); //Нужен для следующего запроса
Document doc = res1.parse();
Element element = doc.selectFirst("#bootjs");
String script = element.toString();
Pattern pattern = Pattern.compile("\"SITE_CONFIG_LOCATION\":\"([^\"]+?)\"");
Matcher matcher = pattern.matcher(script);
//System.out.println(script);
String config_path = null;
while (matcher.find()) {
config_path = matcher.group(1).toString();
break;
}
return config_path;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment