Comments (3)
批量入库时,确实是以这一批数据的第一条作为 “模板”。
对于临时解决这个问题,则需要对每个字段都进行赋值,即使是None
eg:
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
from feapder.
你好,我在使用框架的时候遇到这样一个现象,可能会是一个潜在的隐患
我是直接在解析体里实例化Item,然后给Item的各个键赋值。
整个解析体会有一些条件分支,如下示例代码所示
一开始我没有注意到,因为大部分情况和我料想的一样
else语句里没有赋值的字段都是自动填充None到数据库的
但是后来发现,有的数据本来key_a, key_b, key_c需要有值的,实际上却只有一个status字段的值是1,其余均为空
定位到上面那张图的代码位置
原因我猜想是这样的,多条数据在一起入库,生成sql语句的时候,选择了列表中第一条记录的key,而第一条记录的key如果是else条件下赋值的,就会只有一个字段被使用,那么这一批一起入库的数据就只有一个字段入库了
不知作者能不能明白我的意思哈哈~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
懂你意思,这个问题我也遇到过。同一批数据入库时,如果key不一样就会有问题。之所以没修复,是因为可以在用的层面注意下就行了。如果框架处理这个,需要遍历每一条数据,把数据按照key归类,当时觉得浪费效率,就没做这个处理。不过现在开源了,用户多了,为了使用体验,后面也可以考虑处理下
from feapder.
嗯确实确实,这个用的时候注意下可以解决,不过第一次用确实容易踩坑而且不太容易察觉哈哈。这个框架真棒,希望越来越好!
from feapder.
Related Issues (20)
- 使用selenium或者PlayWright 都指定了thread_count 但是无法打开多个浏览器
- 在使用playwright的时候总是报错,sync_playwright().start()这里会报错 HOT 2
- UpdateItem 批量更新数据问题 HOT 2
- 解析不了web,python3.11、feapder1.8.5 HOT 1
- 因为代理实效导致的重试还是使用实效的那个IP HOT 5
- 单机多进程模式下,MySQL 连接报错:通常每个套接字地址(协议/网络地址/端口)只允许使用一次 HOT 1
- 想要在start()启动爬虫的时候可以携带可变的初始url作为参数
- render=True报错 HOT 3
- 如何在自定义下载器中启用setting中配置的代理? HOT 3
- feapder v1.8.8 使用代理IP报错? HOT 2
- mysql 查询 有bug HOT 2
- 指定parser_name和callback不生效
- 關於BatchSpider
- PLAYWRIGHT 默认开启无痕 HOT 2
- feapder requests能支持curl_cffi类似绕过指纹吗 HOT 2
- 批次爬虫获取redis中的任务时一直阻塞,任务存在就是不去执行,重新执行采集程序又正常了 HOT 3
- response.re_first()报错 HOT 1
- 浏览器渲染功能是否可以添加支持drissionpage库? HOT 4
- mongo使用url连接副本集,不能使用yeild item来进行存储 HOT 1
- 如何让AirSpider在调用时每次的浏览器实例都为最新 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from feapder.