-
Notifications
You must be signed in to change notification settings - Fork 0
/
moodle.py
62 lines (43 loc) · 1.47 KB
/
moodle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from time import sleep
from selenium import webdriver
options = webdriver.ChromeOptions()
profile = {
"plugins.plugins_list": [{
"enabled": False,
"name":"Chrome PDF Viewer"
}],
"download.default_directory" : "/home/kds/"
}
options.add_experimental_option("prefs", profile)
driver = webdriver.Chrome(chrome_options=options)
URL = 'http://moodle.utfpr.edu.br/'
def login(driver):
username = input('login: ')
password = input('senha: ')
username_input = driver.find_element_by_id('username')
password_input = driver.find_element_by_id('password')
username_input.send_keys(username)
password_input.send_keys(password)
username_input.submit()
def get_disciplines_url(driver):
sleep(2)
links = driver.find_elements_by_css_selector('.type_system .type_course > p > a')
hrefs = set()
for link in links:
hrefs.add(link.get_property('href'))
return list(hrefs)
def get_pdfs(driver):
disciplines_url = get_disciplines_url(driver)
css = 'li.activity.resource .activityinstance > a'
for discipline in disciplines_url:
driver.get(discipline)
activities = driver.find_elements_by_css_selector(css)
for activity in activities:
img = activity.find_element_by_tag_name('img')
src = img.get_property('src')
src_splitted = src.split('/')
if src_splitted[-1] == 'pdf-24':
activity.click()
driver.get(URL)
login(driver)
get_pdfs(driver)