Advertisement
Guest User

Untitled

a guest
May 29th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.71 KB | None | 0 0
  1.  
  2. from selenium import webdriver
  3.  
  4. from selenium.webdriver.common.keys import Keys
  5.  
  6. #!/usr/bin/env python3
  7.  
  8. # -*- coding: utf-8 -*-
  9.  
  10. """
  11.  
  12. Created on Sun May 28 21:26:50 2017
  13.  
  14. @author: Pranavtadepalli and houd163
  15.  
  16. """
  17.  
  18. #if int(ss)>=90: driver.quit()
  19.  
  20. #solution=urllib.r equest.urlopen('https://www.wolframalpha.com/input/?i='+problem.replace('×','*')).read()
  21.  
  22. #solution=soup(solution)
  23.  
  24. #print(solution.find_all(class_="ng-isolate-scope"))
  25.  
  26. from selenium import webdriver
  27.  
  28. from selenium.webdriver.common.by import By
  29.  
  30. from selenium.webdriver.common.keys import Keys
  31.  
  32. from selenium.webdriver.support.wait import WebDriverWait
  33.  
  34. from selenium.webdriver.support import expected_conditions as EC
  35.  
  36. from selenium.webdriver.common.keys import Keys
  37.  
  38. import time
  39.  
  40. from bs4 import BeautifulSoup as soup
  41.  
  42. import urllib.request
  43.  
  44. driver = webdriver.Ie("C:\\Users\\agzsc\\Google Drive\\IEDriverServer.exe")
  45.  
  46. driver.get('https://www.ixl.com/')
  47.  
  48. username = driver.find_element_by_name("username")
  49.  
  50. password = driver.find_element_by_name("password")  
  51.  
  52. username.send_keys("prantadepa@losgatos")
  53.  
  54. password.send_keys("17802249")
  55.  
  56. driver.find_element_by_id("qlsubmit").click()
  57.  
  58. def solveIXL(problem):        
  59.  
  60.     try:
  61.  
  62.         solution=int(problem.split(':')[1].split(' ')[0])*int(problem.split(':')[1].split(' ')[2])
  63.  
  64.     except:
  65.  
  66.         time.sleep(1)
  67.  
  68.         try:
  69.  
  70.             solution=int(problem.split(':')[1].split(' ')[0].split('*')[0])*int(problem.split(':')[1].split(' ')[0].split('*')[1])
  71.  
  72.         except:
  73.  
  74.             solution=1
  75.  
  76.     return solution
  77.  
  78. for elem in range(25):
  79.  
  80.     driver.execute_script('''window.open("https://www.ixl.com/math/grade-3/multiply-by-6","_blank");''')
  81.  
  82.     driver.switch_to_window(driver.window_handles[1+elem])
  83.  
  84.     source=soup(driver.page_source,'lxml')
  85.  
  86.     time.sleep(1)
  87.  
  88.     ss=source.findAll("span", {"id": "currentscore"})[0].get_text()
  89.  
  90.     ss=int(ss)
  91.  
  92.     print(ss)
  93.  
  94.     if ss>=90: driver.quit()
  95.  
  96.     if 1==1:
  97.  
  98.         problem = None
  99.  
  100.         while problem is None:
  101.  
  102.             try:
  103.  
  104.                 source=soup(driver.page_source,'lxml')
  105.  
  106.                 problem=source.find_all(class_="math")[0].get_text().replace('×','*').replace('\xa0','')
  107.  
  108.             except:
  109.  
  110.                 driver.execute_script('''location.reload();''')
  111.  
  112.            
  113.  
  114.     solution=solveIXL(problem)
  115.  
  116.     answer=driver.find_element_by_class_name("fillIn")
  117.  
  118.     answer.send_keys(solution)
  119.  
  120.     time.sleep(1)
  121.  
  122.     try:
  123.  
  124.         driver.find_elements_by_xpath("//button[contains(text(), 'Submit')]")[1].click()
  125.  
  126.     except:
  127.  
  128.         driver.find_elements_by_xpath("//button[contains(text(), 'Submit')]")[0].click()
  129.  
  130.     time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement