|
- db = MySQLdb.connect(host = "XXX", user = "XXX", passwd = "XXX", db = "xxx", port = 3306)
- db.set_character_set('utf8')
- print('连接上了!')
- #获取操作游标
- cursor = db.cursor()
- cursor.execute('SET NAMES utf8;')
- cursor.execute('SET CHARACTER SET utf8;')
- cursor.execute('SET character_set_connection=utf8;')
-
- for font in fonts:
- td = font.parent
- a = td.a
- href = "http://www.xxx.cn"+a['href']
- title = a['title']
- publishDate = td.span.text
- # 获取文章详情信息
- detailsContent = r.get(href).content
- detailsSoup = BeautifulSoup(detailsContent, "html.parser")
- detailsFont = detailsSoup.find('font', id='zoom').text
- print detailsFont
- createDate = time.strftime('%Y-%m-%d ',time.localtime(time.time()))
- hashCode = str(hash("xxx")+hash(title)+hash(href)+hash(publishDate))
- print type(hashCode)
- insert_color = ("INSERT INTO t_monitoring_dynamic_info (hashcodeUnique) VALUES (%s)")
- data_color = (hashCode)
- cursor.execute(insert_color, data_color)
- db.commit()
-
- cursor.close()
- db.close()
复制代码 小弟刚学python,插入总是报错- TypeError: not all arguments converted during string formatting
复制代码- print type(hashCode) 是<type 'str'>
复制代码 数据库中的hashcodeUnique字段也是 varchar类型,不明白为啥总是报这个错误
|
|