将RegEx中的缺失值插入SQLite3

时间:2014-10-24 12:13:53

标签: python regex sqlite urllib2 missing-data

我使用urllib / regex解析了几个网页,并将信息(应用程序10个变量)从Python保存到SQLite3。某些网页缺少某些信息,因此RegEx在这种情况下没有返回任何内容。在我将所有信息保存到sqlite后,我只获得了数据集,其中所有列都是非缺失值。如何将缺少值的数据集保存到sqlite?

我的数据库必须如下所示:

apple pier cherry
 2    3     5
 1          4
      2     7
 5    4     6
 1
 2    3     7

我的代码:

for page in webpages:
    apples = findall(r'some regex',str(page))
    piers = findall(r'some regex',str(page))
    cherries = findall(r'some regex',str(page))

    for apple, pier, cherry in zip(apples, piers, cherries):
        c.execute('''insert into sometable (apple, pier, cherry) values(?,?,?)''',(apple, pier, cherry))         

1 个答案:

答案 0 :(得分:0)

将空字符串作为params传递给bind ..

cur.execute("insert into table values ('asd',3,'','%s','%s')",('asdf','dd'));