From c5035c45efee93704dfd571785e0d80485551f24 Mon Sep 17 00:00:00 2001 From: sigvartmh Date: Thu, 11 May 2017 16:07:13 +0200 Subject: [PATCH] add user login --- itl_scrape.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/itl_scrape.py b/itl_scrape.py index 986984c..51f1f12 100644 --- a/itl_scrape.py +++ b/itl_scrape.py @@ -2,15 +2,29 @@ import os import re import argparse import requests as rq +import mechanicalsoup as ms + from bs4 import BeautifulSoup as bs +from getpass import getpass -key = input("Enter sessionID: ") -print(key) -cookie={"JSESSIONID": key} +url = "https://innsida.ntnu.no/lms-ntnu" +b = ms.StatefulBrowser() + +login = input("Enter NTNU-username: ") +password = getpass("Enter your NTNU-password: ") +b.open(url) +b.select_form("form[name=f]") +b["feidename"]=login +b["password"]=password +b.submit_selected() +b.select_form("form[action=https://sats.itea.ntnu.no/sso-wrapper/feidelogin]") +b.submit_selected() +key = b.session.cookies.get_dict() + +cookie={"JSESSIONID": key["JSESSIONID"]} print(cookie) -login = "https://innsida.ntnu.no/lms-ntnu" -r = rq.get(login, cookies=cookie) +r = rq.get(url, cookies=cookie) print(r.url) tc = r.request.headers["Cookie"].split(";") @@ -20,6 +34,8 @@ print(itl_cookies) base_url = "https://ntnu.itslearning.com/" + + url = input("Enter folder link: ")