Created
July 16, 2017 18:13
-
-
Save max-kov/82a90a0c3ddce2674089327433394482 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) |
i download the python file then?
<script src="https://gist.github.com/max-kov/82a90a0c3ddce2674089327433394482.js"></script>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how do i use it?