My python code is not inserting data into the databse. I have no idea why?
<p>My code is just making a database which stores links. But due to some reason when i open the database, it is an empty table. I have no idea why does this happen.</p>

<p>Not Causing any trouble</p>

<pre><code>#!/usr/bin/python
import urllib2
from BeautifulSoup import *
import sqlite3

count = 0
ecount = 0
aj = list()
error = list()
run = 1
</code></pre>

<p>The sql connect</p>

<pre><code>conn = sqlite3.connect('example.db')
cur = conn.cursor()
sql = '''CREATE TABLE URL (LINKS CHAR(512), ID INT(512))'''
cur.execute(sql)
</code></pre>

<p>Not Causing any trouble</p>

<pre><code>def retriver(durl):
    newurl = list()
    url = durl
    notpar = {"#", "None", "NONE", "javascript:void(0)"}


    hl = urllib2.urlopen(url, None)
    html = hl.read()
    hl.close()
    soup = BeautifulSoup(html)
    tags = soup('a')
</code></pre>

<p>THIS IS THE SCRAPER</p>

<pre><code>    for tag in tags:
        new = tag.get('href', None)
        newurl.append(new)
        for i in newurl:
            try:
                if i[0] == "/" and i[0:3] != "www":
                    if i[len(a)] == "/":
                        i = url[0:len(url)-1] + i
                    else:
                        i = url + i
                if i[0:3] == "www":
                    i = "/" + i
                if "." not in list(i):
                    continue
                if i[0] == "/":
                    i = i[1:len(i)]
                if i[0:4] != "http":
                    if i[len(i)] != "/":
                        i = "/" + i
</code></pre>

<p>THIS IS WHERE THE PROBLEM STARTS</p>

<pre><code>                if i not in aj:
                    if i not in notpar:
                        aj.append(i)
                        print i
                        count += 1
                        sql = '''INSERT INTO URL(LINKS, ID) VALUES (%s, %d)'''
                        sqldata = (i, count)
                        cur.execute(sql, sqldata)
                        conn.commit()
            except:
                error.append(i)
                ecount += 1
                global ecount
    global count
    global aj

u = raw_input('Enter the url :: ')
aj.append(u)
retriver(u)
</code></pre>

<p>Not Causing any trouble</p>

<pre><code>while True:

    try:
        retriver(aj[run])
        run += 1
        if run &gt; 20:
            break
        print run
    except:
        run += 1
        retriver(aj[run])
        print run
</code></pre>

<p>In this line:</p>

<pre><code>sql = '''INSERT INTO URL(LINKS, ID) VALUES (%s, %d)'''
</code></pre>

<p>Try changing it to this:</p>

<pre><code>sql = '''INSERT INTO URL(LINKS, ID) VALUES (?, ?)'''
</code></pre>

<p>This post <a href="http://stackoverflow.com/questions/13613037/is-this-python-code-vulnerable-to-sql-injection-sqlite3">here</a> references that the database's API for parameter substitution uses a <strong>?</strong> rather than the <strong>%s</strong> or <strong>%d</strong> symbol.</p>

python sql database sqlite