-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniHelper_dbLezioni.py
More file actions
45 lines (40 loc) · 1.48 KB
/
UniHelper_dbLezioni.py
File metadata and controls
45 lines (40 loc) · 1.48 KB
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
from selenium import webdriver
import sqlite3 as database
import time
def check(a, b):
for text in a:
if text in b:
return 1
return 0
conn = database.connect('UniHelper.db')
c = conn.cursor()
anno = time.strftime("%Y")
url = f"https://www.unipg.it/didattica/offerta-formativa/offerta-formativa-{anno}-{str(int(anno[2]+anno[3])+1)}?ricerca=on&annoregolamento={anno}&dipartimento=&lingua=&tipocorso=&sede=&nomecorso=&cerca=Cerca"
opt = webdriver.ChromeOptions()
prefs = {"profile.managed_default_content_settings.images": 2}
opt.add_experimental_option("prefs", prefs)
opt.headless = True
driver = webdriver.Chrome('chromedriver', options=opt)
driver.get(url)
avoid = ["Accesso:", "Modalità Didattica:", "Lingua: "]
Xpath = "//td"
rows = 1+len(driver.find_elements_by_xpath(Xpath))
cols = len(driver.find_elements_by_xpath(Xpath))
corso = []
x = ""
for field in driver.find_elements_by_xpath(Xpath):
if field.text and not check(avoid, field.text):
# print(field.text.strip())
if not check(["LM-", "L/", "L-"], field.text):
if x:
print(corso[0], corso[1], corso[2], x)
c.execute(
'INSERT OR IGNORE INTO CorsoLaurea(corso_laurea,dipartimento,classe) VALUES (?,?,?);', (corso[0], corso[1], x))
conn.commit()
x = ""
corso = []
corso.append(field.text.strip())
else:
x = x+field.text.strip()+"#"
print(rows, cols)
conn.close()