【学习打卡】第8天 Scrapy打造搜索引擎 items的定义和使用
2022/8/13 3:22:55
本文主要是介绍【学习打卡】第8天 Scrapy打造搜索引擎 items的定义和使用,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
课程名称:Scrapy打造搜索引擎(分布式爬虫)
课程章节:items的定义和使用
主讲老师:bobby
课程内容:
今天学习的内容包括:items的定义和使用
课程收获:
1.Item创建
1.Item作用
提供了额外的保护机制来避免拼写错误导致的未定义字段错误
可以更为方便的操作和保存item中的数据,以及满足scrapy其他相关功能的支持
2.代码
import scrapy class ArticleSpiderItem(scrapy.Item): # define the fields for your item here like: # name = scrapy.Field() pass class JobBoleArticleItem(scrapy.Item): title = scrapy.Field() create_date = scrapy.Field() url = scrapy.Field() url_object_id = scrapy.Field() # 网页URL不定长,则通过MD5生成id,使得URL地址存储为定长字符 front_image_url = scrapy.Field() front_image_path = scrapy.Field() # 保存图片本地地址 praise_nums = scrapy.Field() comment_nums = scrapy.Field() view_nums = scrapy.Field() tags = scrapy.Field() content = scrapy.Field()
3.jobbole.py中使用自定义的Item
1.代码截图
2.查看Item对象的值
4.yield Item——Scrapy自动将Item交给对应的Pipeline进行数据处理和保存
这篇关于【学习打卡】第8天 Scrapy打造搜索引擎 items的定义和使用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-28Elasticsearch - kibana画图
- 2024-03-28我最近买的书里面带的CD盘,放电脑里后,说是0字节,但是可以播放,不能把里面的东西复制出来
- 2024-03-26sqlalchemy.exc.objectnotexecutableerror: not an executable object
- 2024-03-26no dashboards are active for the current data set
- 2024-03-26torch sum
- 2024-03-26format' is not a recognized built-in function name
- 2024-03-26sources list kali
- 2024-03-26matlab p code
- 2024-03-26mean of empty slice
- 2024-03-26unable to attach or mount volumes: unmounted volumes