2015-11-01 16 views
0

我爲了用下面的命令來創建自己的數據庫編寫Web內容這是我的腳本的一部分:sqlite3的並不在我的桌子

hostName='mywebsite.com' 
cur=con.cursor() 
cur.execute('SELECT hostName FROM mytable WHERE hostName="'+hostName+'"') 
data=cur.fetchall() 
cont=session.get('http://'+hostName).content 
cur.execute('INSERT INTO mytable (hostName,content) VALUES (\''+hostName+'\',\''+str(cont)+'\')') 

但是,當我得到的網站內容時,內容不是SH不寫入表ORT。

也許有一個參數大於TEXT

回答

2

從不將列的內容直接格式化爲SQL語句。改用佔位符:

cur.execute("SELECT hostName FROM mytable WHERE hostName=?", [hostName]) 
data = cur.fetchall() 
cont = session.get('http://%s' % hostName).content 
cur.execute("INSERT INTO mytable (hostName,content) VALUES (?,?)", [hostName, cont])