【python爬虫】scrapy入门2--自定义item

items.py

1
2
3
4
5
6
class LianhezaobaospyderItem(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    # pass
    body=scrapy.Field()
    link=scrapy.Field()

爬虫.py

from .. import items

def parse_news(self,response):
    item=items.LianhezaobaospyderItem()                
    item['body']=response.xpath("//div[@class='xx']/text()").get()
    item['link']=response.url
    yield item    

item和字典类似,数据量大时,字典可能键值对错误

posted @   HuaBro  阅读(331)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示