I am trying to INSERT some values into my database
urls =("http://www.**********.net/?page=match")
hdr = {'User-Agent': 'Mozilla/5.0'}
req = urllib2.Request(urls,headers=hdr)
page = urllib2.urlopen(req)
soup = BeautifulSoup(page)
tournament = soup.find('div',{'class':['content-body']})
match_times = tournament.find_all("div", style = "width:10%; float:left;")
match_names = tournament.find_all("div", style = "width:46%; float:left; margin-left:2%; margin-right:2%")
tournys = tournament.find_all("div", style = "width:40%; float:left; overflow:hidden;")
for element in zip(match_times, match_names, tournys):
results = element[0].text, element[1].text, element[2].text
matchday=datetime.strptime(results[0], "%d/%m/%y").strftime("%d-%m-%Y")
info= results[1],results[2],matchday
conn= MySQLdb.connect(host='localhost',user='root',passwd='',db='sport')
c = conn.cursor()
query = "INSERT INTO todaysmatches (match, tournament, matchdate) VALUES (%s,%s,%s)"
c.executemany(query, info)
conn.commit()
conn.close()
print info
print '==================='
match is a varchar(150) , tournament varchar(150) and matchdate is DATE
this is an example of a printed info:
(u'\n\xa0bestest \n9 - 16\ntryPANTS\xa0\n\n', u'\xa0Razer CS:GO Tournament', '08-12-2013')
info= results[1].strip(), results[2].strip(), matchdayand try what @avoid3d mentioned - Syed Habib Minfo= str(results[1].strip()), str(results[2].strip()), matchdayandc.execute(query, info). I think it should work. - Syed Habib M