0

I'm trying to scrape my school website with the requests module. In order to enter in my account, I have to submit my username and password. I tryed to do this with selenium, but when I try to get the html content after I logged in, it gives me the html of the log in page.

This is the html code of the box where I have to put my data:

<input class="input_account idesk-force-focus placeholder" 
type="text" id="login" placeholder="Codice personale/ Email/ Badge" 
name="login" value="" size="56" tabindex="2" 
style="border-radius: 5px; border: 1px solid #aaaaaa;
 height: 30px; font-size: 16px; padding-left: 4px; 
width: 490px;   margin-left: 60px; ">

This is the selenium code


def SelLog():

    driver = webdriver.Chrome()
    driver.get("https://web.spaggiari.eu/home/app/default/menu_webinfoschool_studenti.php")

    #keys
    username = driver.find_element_by_xpath("//*[@id='login']")
    password = driver.find_element_by_xpath("//*[@id='password']")
    confirm = driver.find_element_by_xpath("//*[@id='login-container']/div[2]/div/div/input")

    #fill element
    username.send_keys(USERNAME)
    password.send_keys(PASSWORD)
    confirm.click()
    time.sleep(1)


    homeworks = driver.find_element_by_xpath('//*[@id="data_table"]/tbody/tr[14]/td[4]/a')
    homeworks.click()



    contentSel = "https://web.spaggiari.eu/fml/app/default/agenda_studenti.php"
    contentReq = requests.get("https://web.spaggiari.eu/fml/app/default/agenda_studenti.php")
    print(contentReq)

    response = urllib.request.urlopen(contentSel)
    html = response.read()


So I tryed with some other modules, but same result. I searched on internet for some answers, and I found out that the requests module is perfect for this.

So I tryed this code, found on stackoverflow:

payload = {"login":USERNAME, "password": PASSWORD}

def req():
    username = USERNAME
    password = PASSWORD
    url = URL
    params = {"action":"process"}
    session = requests.session()
    r = session.post(URL, data = payload, params = params)
    account = session.get("https://web.spaggiari.eu/home/app/default/menu_webinfoschool_studenti.php?custcode=")
    print(account.content)

But still no results.

Can somebody help me with this?

ps Sorry for the english

0 Answers0