Advertisement
EdmundC

grade

Aug 28th, 2024 (edited)
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.11 KB | None | 0 0
  1. import subprocess
  2. import sys
  3. from selenium import webdriver
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.common.keys import Keys
  6. from bs4 import BeautifulSoup
  7. import time
  8.  
  9. # Function to install packages
  10. def install(package):
  11.     subprocess.check_call([sys.executable, "-m", "pip", "install", package])
  12.  
  13. # List of required packages
  14. required_packages = ['selenium', 'beautifulsoup4']
  15.  
  16. # Install packages if not already installed
  17. for package in required_packages:
  18.     try:
  19.         __import__(package)
  20.     except ImportError:
  21.         print(f"Installing {package}...")
  22.         install(package)
  23.  
  24. # Embed the password directly in the code (use with caution)
  25. username = "echenault"
  26. password = "One98four!!!"  # Directly embedded password
  27.  
  28. # Set up Selenium WebDriver (e.g., using Chrome)
  29. driver = webdriver.Chrome()
  30.  
  31. # Open the SAML login page
  32. driver.get('https://evansvilledayschool.instructure.com/login/saml')
  33.  
  34. # Wait for the SAML login page to load (adjust time as necessary)
  35. time.sleep(5)
  36.  
  37. # Find the username and password fields and fill them in
  38. username_field = driver.find_element(By.NAME, "username")  # Change to the actual field name or ID
  39. password_field = driver.find_element(By.NAME, "password")  # Change to the actual field name or ID
  40.  
  41. username_field.send_keys(username)
  42. password_field.send_keys(password)
  43.  
  44. # Submit the login form
  45. password_field.send_keys(Keys.RETURN)
  46.  
  47. # Wait for the login to complete and for the grades page to load
  48. time.sleep(10)  # Adjust the sleep time as needed
  49.  
  50. # Navigate to the grades page
  51. driver.get('https://evansvilledayschool.instructure.com/courses/941/grades')
  52.  
  53. # Extract the page source
  54. page_source = driver.page_source
  55.  
  56. # Parse the page with BeautifulSoup
  57. soup = BeautifulSoup(page_source, 'html.parser')
  58.  
  59. # Find the element with the grade percentage
  60. grade_element = soup.find('span', class_='grade')
  61.  
  62. if grade_element:
  63.     # Extract and print the grade percentage
  64.     grade_percentage = grade_element.text.strip()
  65.     print(f"Grade: {grade_percentage}")
  66. else:
  67.     print("Grade not found.")
  68.  
  69. # Close the browser
  70. driver.quit()
  71.  
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement