代码
# -*- coding:utf-8 -*-
import pymysql.cursors
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
# Connect to the database
connection = pymysql.connect(host='localhost',
user='root',
password='',
db='gongchang',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
try:
with connection.cursor() as cursor:
sql = "INSERT INTO `gc_spider` (`name`, `url`,`pid`) VALUES (%s, %s, %s)"
cursor.execute(sql, ('苏州东菱振动试验仪器有限公司', '','xlTM-TogKuTw8WCD3fpSm0-xsvPsv9c3BQmd'))
connection.commit()
with connection.cursor() as cursor:
sql = "SELECT count(name) as count FROM `gc_spider` WHERE `name`=%s"
cursor.execute(sql, ('苏州东菱振动试验仪器有限公司',))
result = cursor.fetchone()
if(result['count']>0):
print('have')
else:
print('no')
finally:
connection.close()
网友评论