pywhois将结果解析为mysql

时间:2014-05-13 13:57:47

标签: python mysql-python pywhois

对不起,如果你考虑转发,非常简单的代码,我怀疑这里也是一个微不足道的错误,但不能继续前进:

import whois
import MySQLdb
db = MySQLdb.connect(host="localhost", user="root",  passwd="pass", db="whois")
cur = db.cursor()
wi = whois.whois("google.com")
cur.execute("""INSERT INTO wrec (dname, wfull, dns) VALUES (%s, %s, %s)""") , (wi.domain_name, wi.text, wi.name_servers)

结束于:

_mysql_exceptions.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, %s, %s)' at line 1")
如上所述,怀疑是微不足道的错误。有什么建议?非常感谢提前

1 个答案:

答案 0 :(得分:1)

您将获取的Whois变量放在执行函数之外!

变化:

cur.execute("""INSERT INTO wrec (dname, wfull, dns) VALUES (%s, %s, %s)""") , (wi.domain_name, wi.text, wi.name_servers)

要:

cur.execute("""INSERT INTO wrec (dname, wfull, dns) VALUES (%s, %s, %s)""", (wi.domain_name, wi.text, wi.name_servers))

修改

不要忘记添加:

db.commit()

在剧本的最后。