New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
item存储的问题 #57
Comments
批量入库时,确实是以这一批数据的第一条作为 “模板”。 item = Item()
item.create_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
if 'hhh' in response.text:
item.status = 1
item.key_a = response.xpath('...')
item.key_b = response.xpath('...')
item.key_c = response.xpath('...')
else:
item.status = 0
item.key_a = None
item.key_b = None
item.key_c = None |
嗯确实确实,这个用的时候注意下可以解决,不过第一次用确实容易踩坑而且不太容易察觉哈哈。这个框架真棒,希望越来越好! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
你好,我在使用框架的时候遇到这样一个现象,可能会是一个潜在的隐患
我是直接在解析体里实例化Item,然后给Item的各个键赋值。
整个解析体会有一些条件分支,如下示例代码所示
一开始我没有注意到,因为大部分情况和我料想的一样
else语句里没有赋值的字段都是自动填充None到数据库的
但是后来发现,有的数据本来key_a, key_b, key_c需要有值的,实际上却只有一个status字段的值是1,其余均为空
定位到上面那张图的代码位置
原因我猜想是这样的,多条数据在一起入库,生成sql语句的时候,选择了列表中第一条记录的key,而第一条记录的key如果是else条件下赋值的,就会只有一个字段被使用,那么这一批一起入库的数据就只有一个字段入库了
不知作者能不能明白我的意思哈哈~
The text was updated successfully, but these errors were encountered: