截止目前,应该已经成功获取到了真实的地址
为了避免多次调用接口,将地址存入数据库
(以前没写过python,所以语法啥的不太好看可能,能用就行O(∩_∩)O哈哈~)
写python的时候if一定要注意开头的空格!
db = MySQLdb.connect("localhost", "root", "root", "yingshi", charset='utf8' )
cursor = db.cursor()
sql_query = "select * from source where url =\'%s\' and domain =\'%s\' and source = \'%s\'" % (url,domain,source)
count=cursor.execute(sql_query)
count=int(count)
if count == 0:
#更新
#result = cursor.fetchone()
#sql_update="update source set url=\'%s\' , domain =\'%s\' , source = \'%s\'" % (url,domain,source) %"where id = %s " % result[0]
#增加
sql = "INSERT INTO SOURCE(URL, DOMAIN, SOURCE) VALUES (\'%s\', \'%s\', \'%s\')" % (url,domain,source)
cursor.execute(sql)
网友评论