python爬虫:scrapy自定义item
items.py
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和字典类似,数据量大时,字典可能键值对错误
相关推荐
javaraylu 2020-06-28
ZHANGRENXIANG00 2020-06-28
Catastrophe 2020-06-26
andrewwf 2020-05-30
ZHANGRENXIANG00 2020-05-11
andrewwf 2020-11-11
Arvinzx 2020-10-28
CycloneKid 2020-10-27
paleyellow 2020-10-25
baifanwudi 2020-10-25
heyboz 2020-10-21
wumxiaozhu 2020-10-16
ZHANGRENXIANG00 2020-07-27
zhangll00 2020-07-05
Catastrophe 2020-06-26
fangjack 2020-06-25
andrewwf 2020-06-16