blob: 5ff9d82c4c3fc64cc0a284a82bf9785a190a7b21 (
plain)
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
|
#!/usr/bin/env python3
#-*- coding:utf-8 -*-
import http.cookiejar
import urllib.request
import urllib.parse
import config
from bs4 import BeautifulSoup
cookiejar = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookiejar))
urllib.request.install_opener(opener)
data = urllib.parse.urlencode({'username': config.username, 'password': config.password})
data = data.encode('utf-8')
request = urllib.request.Request(config.moodleurl + 'login/index.php')
# Login
f = urllib.request.urlopen(request, data)
# Scrapen starten
f = urllib.request.urlopen(config.moodleurl + 'user/index.php?perpage=999999&mode=1&id=' + str(config.courseid))
soup = BeautifulSoup(f.read())
# iterieren und speichern
users = dict()
for cell in soup.find_all('td', class_='content'):
thisuser = cell.find_all('div', class_='username')
if thisuser:
thisuser = thisuser[0]
if thisuser:
thisuser = thisuser.string
thismail = cell.find_all('a')
if thismail:
thismail = thismail[0]
if thismail:
thismail = thismail.string
users[thisuser] = thismail
f = open('data/users.txt', mode='w', encoding='utf-8')
f.write(str(users))
f.close()
|