I want to execute this query in Python:
cur=self.con.execute("insert into %s(url_id,url_name,url_title) values(%d,'%s','%s')" % (table,url_i,url_n,url_t))
Here, I'm inserting url id, url name and url title in the columns url_id, url_name and url_title respectively. The id and url are getting inserted pretty fine but not the url_title. The url_title column is simply blank.
If we, just for fun, swap the positions of url_n and url_t then the problem persists! I thought the problem might be related to the url_title column itself but this little experiment proves the problem might be with url_t variable.
We get the value of url_t by extracting the actual url title of the particular webpage using BeautifulSoup and Urllib2. Here's the function if you are interested:
def title(self,soup):
url_title=soup.title.string
return url_title
This returns the url title which I want to insert in the database.
I created the table, in which we intend to insert the values, using Django models. Here's the models.py file:
class url_list(models.Model):
url_id=models.IntegerField()
url_name=models.CharField(max_length=200)
url_title=models.CharField(max_length=200)
def __unicode__(self):
return self.url_name
So, what am I doing wrong?
execute()call.