上周selenium+phantomjs+python3简单爬取一个网站,往数据库写数据遇到以下两个问题,记录一下:  

  报错一:Data truncated for column 'update_time' at row 1

  抓网站英文版的时候,因为一个标题太长报错,title字段类型为varchar默认的255,改为2048或者按照实际改小一点。问题解决。

  报错二: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

  虽然上面改了,在同一处还是报错,现在错误是“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 'AGREEMENT\nAMONG THE SHAREHOLDERS OF\nMEDIA EAGLE LIMITED;\nAND\n(2) DISCLOSEABLE TR' at line 1”原始insert语句如下:

sql = "REPLACE INTO crawl_record (`type`, `title`, `create_time`, `update_time`) VALUES ('%s', '%s', '%s', '%s')"

  near后面的一串是要被插入的标题,可见这个标题不仅长,里面还有特殊字符。sql语句使用的单引号,是无效的,改为双引号,改为双引号,最好每个字段用英文下的波浪线``包起来,以免字段设置了关键字。sql改为:

sql = 'REPLACE INTO crawl_record (`type`, `title`, `create_time`, `update_time`) VALUES ("%s", "%s", "%s", "%s")'

  爬取数据,存储数据,各种坑。爬取的时候一定要先一页页的爬取没问题后,再翻页批量爬取,此时可能还会有坑;存数据的时候,一定按标准书写sql,若爬取重要数据,众多数据,数据库表设计一定要让公式DB过一下,降低各种无厘头的错误~

mysql插入数据报错一二的更多相关文章

  1. Mysql插入数据报错java.sql.SQLException: Incorrect string value: '\xF0\x9F\x93\x8D\xE6\x88...'

    今天读取solr里面的数据,往mysql插入时报错, Incorrect string value: '\xF0\x9F\x93\x8D\xE8\x88...' for column 'title'  ...

  2. mysql插入数据报错1366

    数据表插入中文数据报错 Warning Code : 1366 Incorrect string value: '\xE5\x9C\xA8' for column 'name' at row 1 原因 ...

  3. mysql插入数据报错IntegrityError: (1062, "Duplicate entry 'xx' for key 'xxxxx'")

    1.问题描述 MySQL插入数据的时候报错,提示如下: IntegrityError: (1062, "Duplicate entry 'xx' for key 'xxxxx'") ...

  4. Mycat+Mysql 插入数据报错 i[Err] 1064 - partition table, insert must provide ColumnList

    使用Navicat连接Mycat 8066 成功插入了分库表和全局表 1.全局表 sql如下: '); '); '); 插入成功! 2.分库表 sql如下: ', null, null, null, ...

  5. 解决mysql插入数据报错[Err] 1146 - Table 'performance_schema.session_status' doesn't exist

    解决办法:1.打开cmd 执行命令cd/ 进入C盘根目录2.dir 查看C盘根目录下文件夹  找到 Program Files文件夹3.cd Program Files 进入该文件夹下 再输入dir ...

  6. mysql插入数据报 (Incorrect string value: '\xB6\xFE' for column 'name' at row 1)

    这是我的表结构 mysql> describe students; +--------+---------------------+------+-----+---------+-------- ...

  7. PL/SQL插入数据报错:Access violation at address 00413A81 in module 'plsqldev.exe'. Read of address 00000000

    前言 今天同事在使用plsql给oracl数据库插入记录时报错:Access violation at address 00413A81 in module 'plsqldev.exe'. Read ...

  8. MYSQL导入数据报错|MYSQL导入超大文件报错|MYSQL导入大数据库报错:2006 - MySQL server has gone away

    导SQL数据库结构+数据时,如果数据是批量插入的话会报错:2006 - MySQL server has gone away. 解决办法:找到你的mysql目录下的my.ini配置文件(如果安装目录没 ...

  9. Mac系统下Mysql存储数据报错 ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect string value

    比如如下mysql操作插入数据: const mysql = require('mysql'); /* createConnection方法创建一个表示与Mysql数据库服务器之间连接的 Connec ...

随机推荐

  1. 【Java杂货铺】用Security做权限极简入门

    原来大多数单体项目都是用的shiro,随着分布式的逐渐普及以及与Spring的天生自然的结合.Spring Security安全框架越受大家的青睐.本文会教你用SpringSecurity设计单项目的 ...

  2. 基于css完成网页的国际化

    css完成国际化 前提 在日常处理国际化的时候,通常是将key通过类似intl.xx(key)转换为对应环境的文案,可是如果需要在css中加入对应逻辑应该怎么做呢(比如在after的伪元素中显示不同的 ...

  3. Elasticsearch Rest模式和RPC模式性能比较

    Elasticsearch 有两种链接模式,即Rest方式(对应端口9200)和RPC方式(对应端口9300)这两种访问效率到底差多少,在同样的业务逻辑下,测试了一波. 用的JMeter进行压力测试 ...

  4. 在Python 中怎么表示一个元素在一个list中的数量?

    commonest = [1,2,2,2,1,3,4,5,1,1] print(commonest.count(1))

  5. 用C语言实现的轴对称变换

    #include<stdio.h> main() { int i,p,n,k,f,c,h,g,w; ][]; ;i<=;i++) { ;p<=;p++) { a[i][p]=i ...

  6. [LC] 47. Permutations II

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  7. JwtUser JwtAuthenticationEntryPoint JwtAuthorizationTokenFilter JwtUserDetailsService AuthenticationController

    package me.zhengjie.core.security; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok ...

  8. js手机浏览器video标签会一直置顶,遮盖住弹出层问题

    <video x5-playsinline="" playsinline="" webkit-playsinline="">&l ...

  9. deeplearning.ai 序列模型 Week 2 NLP & Word Embeddings

    1. Word representation One-hot representation的缺点:把每个单词独立对待,导致对相关词的泛化能力不强.比如训练出“I want a glass of ora ...

  10. VSAN磁盘扩容与收缩

    删除闪存盘后,整个磁盘组都会被删除 假如一个磁盘组里面只有一块HDD盘,删除此HDD盘,磁盘组也只接被删除 可以整体删除整个磁盘组