-
-
Save TheGodOfNoodles/8cc24af7428fedf9b5cb1a7b618da509 to your computer and use it in GitHub Desktop.
dr frost maths python point farmer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from BeautifulSoup import BeautifulSoup | |
import dryscrape | |
import time | |
url = "http://www.drfrostmaths.com/homework/do-question.php?aaid=161230" | |
sess = dryscrape.Session() | |
sess.visit("http://www.drfrostmaths.com/homework/login.php") | |
name = sess.at_xpath('//*[@name="login-email"]') # Where <input name="username"> | |
name.set("email here") | |
password = sess.at_xpath('//*[@name="login-password"]') # Where <input name="password"> | |
password.set("passwd here") | |
# Push the button | |
name.form().submit() | |
while 1: | |
sess.visit(url) | |
time.sleep(1) | |
response = sess.body() | |
soup = BeautifulSoup(response) | |
question = soup.find("script", {"id": "MathJax-Element-1"}).text.encode('utf-8') | |
try: | |
question = question.replace("\\times","*") | |
ans = eval(question) | |
ans_form = sess.at_xpath('//*[@name="numeric-answer-1"]') | |
ans_form.set(ans) | |
print(question) | |
except: | |
button = sess.at_xpath('//*[@id="ma1"]') | |
if button !=None: | |
button.click() | |
for x in range(10): | |
ans_form = sess.at_xpath('//*[@name="numeric-answer-'+str(x)+'"]') | |
if ans_form!=None: | |
ans_form.set(1) | |
print "bad question" | |
sess.at_xpath('//*[@type="submit"]').click() | |
time.sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment