0
我使用json從網絡載入推文。在SQLite3數據庫中存儲帶有引號的推文
import urllib2, json, sqlite3
wFD = urllib2.urlopen('http://rasinsrv07.cstcis.cti.depaul.edu/CSC455/Twitter_2013_11_12.txt')
blankLines = 0
goodLines = 0
numLines = 10000
while numLines > 0:
line = wFD.readline()
numLines = numLines - 1
try:
tweets.append(json.loads(line))
goodLines = goodLines+1
except:
blankLines = blankLines + 1
blankLines
goodLines
我要檢查整個鳴叫的長度,然後將其存儲在一個表中的數據庫使用sqlite3的一個大項。
SingleTable = """Create table SingleTable
(tweet varchar(8038)
);"""
c.execute("drop table if exists SingleTable")
c.execute(SingleTable)
len_strTwt = 0
for tweet in tweets:
str_tweet = str(tweet)
c.execute("insert into SingleTable values (?)", (str_tweet))
if len_strTwt < len(str_tweet):
len_strTwt = len(str_tweet)
len_strTwt
當我試圖存儲它時,我無法做到這一點,因爲有這麼多的雙引號和單引號。我不知道如何使用這裏的退出符號來將它存儲在數據庫中。任何幫助將不勝感激。謝謝。
謝謝,它的工作。 –