J
Jai
from BeautifulSoup import BeautifulSoup
import re, urllib2, MySQLdb
#MySQLdb.escape_string(" ")
import sys
import unicodedata
if __name__=="__main__":
#link = raw_input("Enter the url link: ")
db = MySQLdb.connect("localhost","root","", "ebay")
cursor=db.cursor()
link = "http://www.ebay.com/sch/Mens-Shoes-/93427/i.html?_pppn=r1&_dcat=93427&LH_ItemCondition=1000|1500"
link1 =db.escape_string(link)
page = urllib2.urlopen(link)
soup = BeautifulSoup(page)
Contents = soup.findAll(itemprop = "name")
lst_content = []
for x in Contents:
x = x.string
lst_content.append(x)
Price = soup.findAll(itemprop = "price")
lst_price =[]
for y in Price:
y = y.string
lst_price.append(y)
for x , y in zip(lst_content, lst_price):
sql = """insert into `category` (url, catagory,price) VAlUES ('%s', '%s', '%s')"""%(link1,x,y)
#print sql
sql = unicodedata.normalize('NFKD', sql).encode('ascii','ignore')
#sys.exit(0)
cursor.execute(sql)
db.commit()
db.close()
+++++++++++++++++++++++
error occur
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1")
import re, urllib2, MySQLdb
#MySQLdb.escape_string(" ")
import sys
import unicodedata
if __name__=="__main__":
#link = raw_input("Enter the url link: ")
db = MySQLdb.connect("localhost","root","", "ebay")
cursor=db.cursor()
link = "http://www.ebay.com/sch/Mens-Shoes-/93427/i.html?_pppn=r1&_dcat=93427&LH_ItemCondition=1000|1500"
link1 =db.escape_string(link)
page = urllib2.urlopen(link)
soup = BeautifulSoup(page)
Contents = soup.findAll(itemprop = "name")
lst_content = []
for x in Contents:
x = x.string
lst_content.append(x)
Price = soup.findAll(itemprop = "price")
lst_price =[]
for y in Price:
y = y.string
lst_price.append(y)
for x , y in zip(lst_content, lst_price):
sql = """insert into `category` (url, catagory,price) VAlUES ('%s', '%s', '%s')"""%(link1,x,y)
#print sql
sql = unicodedata.normalize('NFKD', sql).encode('ascii','ignore')
#sys.exit(0)
cursor.execute(sql)
db.commit()
db.close()
+++++++++++++++++++++++
error occur
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'S SIZE 11.5 NEW IN BOX', '$49.99')' at line 1")