Advertisement
Guest User

Example

a guest
Apr 4th, 2017
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. public class Connect {
  2.  
  3. public static void main(String[] args) {
  4.  
  5.     String pageURL = "https://parents.mtsd.k12.nj.us/genesis/parents?tab1=studentdata&action=form";
  6.     String param1 = "&tab2=gradebook";
  7.     String param2 = "&tab3=weeklysummary";
  8.     String param3 = "&studentid=";
  9.     Scanner input = new Scanner (System.in);
  10.     String initURL = "https://parents.mtsd.k12.nj.us/genesis/parents?gohome=true";
  11.     String sID = "not shown";
  12.  
  13.     String URLF = pageURL + param1 + param2 + param3 + sID;
  14.  
  15.     connectTo(URLF);
  16. }
  17.  
  18. public static Document connectTo (String URLF){
  19.  
  20.     String loginURL = "https://parents.mtsd.k12.nj.us/genesis/parents/j_security_check";
  21.     String userDataUrl = URLF;
  22.     String username = "not shown";
  23.     String password = "not shown";
  24.  
  25.     Connection.Response res = null;
  26.     Document doc = null;
  27.  
  28.     try {
  29.  
  30.         res = Jsoup.connect(userDataUrl)
  31.                 .userAgent("Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.4 Safari/537.36")
  32.                 .header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
  33.                 .timeout(500)
  34.                 .method(Connection.Method.GET)
  35.                 .execute();
  36.  
  37.     } catch (IOException io) {io.printStackTrace();}
  38.  
  39.     try {
  40.  
  41.         doc = Jsoup.connect(loginURL)
  42.                 .userAgent("Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.4 Safari/537.36")
  43.                 .referrer("https://parents.mtsd.k12.nj.us/genesis/parents?gohome=true")
  44.                 .cookies(res.cookies())
  45.                 .data("j_username", username)
  46.                 .data("j_password", password)
  47.                 .post();
  48.  
  49.  
  50.     } catch (IOException ioe) {ioe.printStackTrace();}
  51.  
  52.     if (doc != null){
  53.         System.out.print(doc.text());
  54.     }
  55.     return null;
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement