Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.35 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Sun May 28 21:26:50 2017
  5.  
  6. @author: Pranavtadepalli and houd163
  7. """
  8. from selenium import webdriver
  9. from selenium.webdriver.common.by import By
  10. from selenium.webdriver.common.keys import Keys
  11. from selenium.webdriver.support.wait import WebDriverWait
  12. from selenium.webdriver.support import expected_conditions as EC
  13. import time
  14. from bs4 import BeautifulSoup as soup
  15. from bs4 import SoupStrainer
  16. from selenium.webdriver.common.action_chains import ActionChains
  17. import getpass
  18.  
  19. #ui = input('What is your IXL username?\n\n')
  20. #pi = getpass.getpass('\nWhat is your IXL password?\n\n')
  21. ui = 'myusername'
  22. pi = 'mypass'
  23. driver = "C:\\Users\\agzsc\\Documents\\Python Projects\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe"
  24. driver = webdriver.PhantomJS(driver)
  25. driver.get('https://www.ixl.com')
  26.  
  27.  
  28. username = driver.find_element_by_id('qlusername')
  29. password = driver.find_element_by_id('qlpassword')
  30. submit = driver.find_element_by_id('qlsubmit')
  31. print('Logging in')
  32.  
  33. username.send_keys(ui)
  34. password.send_keys(pi)
  35.  
  36. ActionChains(driver).move_to_element(submit).click().perform()
  37. smartscore = 0
  38. x = -1
  39.  
  40. while smartscore<91:
  41.     source = soup(driver.page_source, 'lxml')
  42.     x = x + 1
  43.     time.sleep(1)
  44.     driver.execute_script('''window.open('https://www.ixl.com/math/grade-3/multiply-by-11','_blank');''')
  45.     driver.switch_to_window(driver.window_handles[1+x])
  46.     time.sleep(5)
  47.     print('Getting question')
  48.     problem = source.find('div', class_='math').get_text()
  49.     problem = problem.split(':')[1]
  50.     problem = problem.replace("×", "*")
  51.     problem = problem.replace(" ", "")
  52.     problem = problem.replace("=", "")
  53.     problem = problem.replace(" ", "")
  54.     solution = eval(problem)
  55.     print('The solution is: ' + str(solution))
  56.     print('Submitting answer')
  57.     driver.find_element_by_class_name('fillIn').send_keys(solution)
  58.     try:
  59.         submit = driver.find_elements_by_xpath("//button[contains(text(), 'Submit')]")[1]
  60.     except:
  61.         submit = driver.find_elements_by_xpath("//button[contains(text(), 'Submit')]")[0]
  62.     ActionChains(driver).move_to_element(submit).click().perform()
  63.     smartscore = driver.find_element(by=By.ID, value='currentscore')
  64.     smartscore = int(smartscore.text)
  65.     print("The smartscore is: " + str(smartscore))
  66. print('The IXL is complete!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement