In [1]:
# Code attribution: Yiyin Shen, Tyler Caraza-Harter
# Imports
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import matplotlib.pyplot as plt
import json
In [2]:
# Take a screenshot of the page
service = Service(executable_path="chromedriver-win64/chromedriver.exe")
driver = webdriver.Chrome(service=service)
def visit(url, file = None):
driver.get(url)
body = driver.find_element("tag name", "body")
if file == None:
return body.text
else:
body.screenshot(file + ".png")
plt.imshow(plt.imread(file + ".png"))
print("DONE")
DONE
In [3]:
# Visit and scrape the pages
home = "http://127.0.0.1:5000"
visit(home, "plots.png")
In [4]:
visit(home + "/grades.json")
Out[4]:
'Column not specified.'
In [5]:
visit(home + "/grades.json?col=no")
Out[5]:
'{"1": "0", "2": "0", "3": "0"}'
In [6]:
len(json.loads(visit(home + "/grades.json?col=Exam")))
Out[6]:
389
In [7]:
driver.quit()