I am new to the forum and already having problems.
I am trying to get my data from an htm file into a table in mysql.
Good side is that with the code below I get no errors. Bad side is that the table is not populated.
MySQL is not complaining, Python is not complaining so please if you can take a look at what's hapening with my code...
In addition, all the variables are valid and if i try to print them again they do return with the right values
- Code: Select all
#-*- coding:utf-8 -*-
from bs4 import BeautifulSoup
db = MySQLdb.connect("localhost", "user", "pass", "work", use_unicode=True, charset = "utf8")
cursor = db.cursor()
soup = BeautifulSoup(open('sanitised.htm'))
elements = soup.find_all("div")
for line in elements:
span_list = line.find_all("span")
timestamp = span_list.get_text()
id1 = span_list.get_text().encode('utf-8')
id_res1 = span_list.get_text().encode('utf-8')
id2 = span_list.get_text().encode('utf-8')
id_res2 = span_list.get_text().encode('utf-8')
mytext = span_list.get_text().encode('utf-8')
cursor.execute = ("INSERT INTO chat_tbl VALUES (%s, %s, %s, %s, %s, %s);", (timestamp, id1, id_res1, id2, id_res2, mytext))