Overview
在笔记2中,我们抓取了页面的文章内容,问题来了,如何将撸下来的文章保存呢?其实方法很多,既然抓取到了,就可以把抓到的内容写入本地,或者记录下来之后,传入数据库,等等。这里,我们要看一下Scrapy 框架Item 是如何保存的。
框架结构看一眼
bole/
scrapy.cfg
bole/
__init__.py
items.py
pipelines.py
settings.py
spiders/
__init__.py
...
这里,我们主要用 items, pipeline, setting
来,写代码
item.py 存放一切抓取对象,以Python 字典格式存储
打开瞄一眼
# Define here the models for your scraped items
# See documentation in:
# https://doc.scrapy.org/en/latest/topics/items.html
import scrapy
class BoleItem(scrapy.Item):
# define the fields for your item here like:
# name = scrapy.Field()
pass
打开文件会发现,这