1

I want to create a program where I can check my grades using python and I have the code to web scrape data, but I do not know how to log into this specific website. The website is https://hac.chicousd.org/LoginParent.aspx?page=Default.aspx and if you need it I can give my username and password. I have tried using requests and urllib and neither work. I appreciate any help given.

3
  • You could use Selenium for this: seleniumhq.org Commented May 5, 2018 at 4:08
  • How can I use python with that? Commented May 5, 2018 at 4:43
  • 1
    Well, pip install selenium will get you selenium and continue reading the documentation, it has python code samples to get you started. You'll be using webdriver mostly: seleniumhq.org/docs/03_webdriver.jsp Commented May 5, 2018 at 4:51

3 Answers 3

2

Try using mechanical soup. It allows you to navigate a website just like you would normally.

Sign up to request clarification or add additional context in comments.

Comments

1

As pointed out in the comments, a possibility is to use selenium, a browser manipulation tool. However, you can also use requests.Sessions to send a POST request with a payload of the email, and then a GET request for whatever portal page you wish to view after:

import requests
r = requests.Session()
payload = {'portalAccountUsername':'[email protected]'}
r.post('https://hac.chicousd.org/LoginParent.aspx?page=Default.aspx', data = payload)

Then, with r instance, you can send a GET request to a page on the portal that is only visible to authenticated users:

data = r.get('https://hac.chicousd.org/some_student_only_page').text

Note that the keys of the payload dictionary must all be valid <input> "name" values from the site's HTML.

1 Comment

@OnkarSandhu did you try and send a GET request to a different page after first logging in with r.post? Also, insure that the keys of the dictionary match the name attributes in the HTML.
1

As others have said, you can use selenium. You also should use time to stop the program some seconds before to put your password. First install selenium in you command prompt pip install selenuim and a webdriver (here is the code for chrome pip install chromedriver_installer). Then you could use them in your code.

import selenium
from selenium import webdriver
import time
from time import sleep

Then, you should open the web page with the web driver

browser = webdriver.Chrome('C:\\Users...\\chromedriver.exe')
browser.get('The website address')

The next step is to find the name of the elements on the web page to write your username, password, and the path for the buttons

username = browser.find_element_by_id('portalAccountUsername')
username.send_keys('your email')

next = browser.find_element_by_xpath('//*[@id="next"]')
next.click()

password = browser.find_element_by_id('portalAccountPassword')
time.sleep(2)
password.send_keys('your password')

sing_in = browser.find_element_by_xpath('//*[@id="LoginButton"]')
sing_in.click()

1 Comment

Thanks I got it to work by using selenium. It worked perfectly, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.