在表中添加数字时出错

时间:2017-07-06 10:10:37

标签: sql python-2.7 postgresql

我想得到这个网站的日期,我可以得到它,但它返回错误添加到列。 打印:http://prntscr.com/fsav5h

代码:

page = urllib2.urlopen('https://www.meetup.com/find/events/career-business/?allMeetups=false&radius=50&userFreeform=London&mcId=c1012717&change=yes')
soup = BeautifulSoup(page, 'html.parser')

events = soup.find('div', class_='unit size5of7 ')

A = []

try:
    conn = psycopg2.connect("dbname='meetup' user='postgres' host='localhost' password='root'")
except:
    print 'Unable to connect to the database.'

cur = conn.cursor()

for event in events.findAll('ul', class_="searchResults resetList clearfix"):
    date = event.findAll('li', class_="date-indicator")
    if len(date) != 0:
        A.append(date[0].find(text = True))
        cur.execute("""UPDATE events SET event_date = %s WHERE event_date = '' """ % tuple(A) )
        conn.commit()
        del A[:]

1 个答案:

答案 0 :(得分:0)

试试这个

cur.execute("""UPDATE events SET event_date = '%s' WHERE event_date = '' """, (tuple(A)))