pymysql.err.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 '~urls~(~urlname~, ~urlhref~)values('Wikipedia', 'https://en.wikipedia.org/wiki/W' at line 1")
2016-09-05
你把插入數據庫的代碼注釋掉,然后只是打印名字和網址,看看需要多久。
2016-09-25
代碼一樣,這個是數據庫配置不對嗎
pymysql.err.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 '~urls~(~urlname~, ~urlhref~)values('Wikipedia', 'https://en.wikipedia.org/wiki/W' at line 1")
2016-09-05
values?=?[]? #?輸出所有的詞條對應的名稱和URL屬性 for?url?in?listUrls: #過濾.jpg或.JPG結尾的URL if?not?re.search("\.(jpg|JPG)$",url["href"]): #輸出URL的文字和對應的鏈接 print(url.get_text(),"<----->","https://en.wikipedia.org"+url["href"]) values.append((url.get_text(),"https://en.wikipedia.org"+url["href"])) try: connection?=?pymysql.connect(host="localhost",user="root",password="root",db="wikiurl",charset="utf8mb4") with?connection.cursor()?as?cursor: sql?=?"insert?into?`urls`(`urlname`,`urlhref`)values(%s,%s)" cursor.executemany(sql,values) connection.commit() except: info?=?sys.exc_info() print(info) print(info[0]) print(info[1]) finally: connection.close()上面代碼我換了思路,把mysql操作放在最后來做,同時調用cursor.executemany, 一次可以插入多條記錄