fin = open("dati.xyz","r")
L = fin.readlines()
Ltitle =[]
Lref = []
for i in L:
if 'title' in i:
a=i.replace('
','')
b = a.replace('','')
Ltitle.append(b)
if 'href' in i:
a=i.replace('','')
Lref.append(b)
import MySQLdb
db = MySQLdb.connect("localhost","user","passw","DB" )
cursor = db.cursor()
#cursor.execute('create database if not exists NOME') # non e' richiesto
#cursor.execute('use NOME') #non e' richiesto
tab = "CREATE TABLE webStudenti (Title char(50), Link varchar(100) ) "
cursor.execute(tab)
insert_stmt = ("INSERT INTO webStudenti (Title, Link) " "VALUES (%s,%s)")
for i in range(0,len(Lref)):
data = (Ltitle[i], Lref[i]) # data = (i)?
cursor.execute(insert_stmt, data)
db.commit()
db.close()