forked from Boris-code/feapder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipeline.py
More file actions
51 lines (38 loc) · 1.38 KB
/
Copy pathpipeline.py
File metadata and controls
51 lines (38 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
"""
Created on 2021/3/18 12:39 上午
---------
@summary:
---------
@author: Boris
@email: boris_liu@foxmail.com
"""
from feapder.pipelines import BasePipeline
from typing import Dict, List, Tuple
class Pipeline(BasePipeline):
"""
pipeline 是单线程的,批量保存数据的操作,不建议在这里写网络请求代码,如下载图片等
"""
def save_items(self, table, items: List[Dict]) -> bool:
"""
保存数据
Args:
table: 表名
items: 数据,[{},{},...]
Returns: 是否保存成功 True / False
若False,不会将本批数据入到去重库,以便再次入库
"""
print("自定义pipeline, 保存数据 >>>>", table, items)
return True
def update_items(self, table, items: List[Dict], update_keys=Tuple) -> bool:
"""
更新数据, 与UpdateItem配合使用,若爬虫中没使用UpdateItem,则可不实现此接口
Args:
table: 表名
items: 数据,[{},{},...]
update_keys: 更新的字段, 如 ("title", "publish_time")
Returns: 是否更新成功 True / False
若False,不会将本批数据入到去重库,以便再次入库
"""
print("自定义pipeline, 更新数据 >>>>", table, items, update_keys)
return True