Item 对象是种简单的容器,保存了爬取到得数据
# -*- coding: utf-8 -*-
# Define here the models for your scraped items
#
# See documentation in:
# https://doc.scrapy.org/en/latest/topics/items.html
import scrapy
class SamzhuItem(scrapy.Item):
# define the fields for your item here like:
# name = scrapy.Field()
name = scrapy.Field()
url = scrapy.Field()
# -*- coding: utf-8 -*-
import scrapy
from samzhu.items import SamzhuItem
class SamSpider(scrapy.Spider):
name = "sam"
start_urls = [
"https://maoyan.com/board"
]
def parse(self, response):
print(response.text)
print('>'*50,'sam')
for sel in response.xpath('//*[@id="app"]/div/div/div/dl/dd'):
item = SamzhuItem()
item['name'] = sel.xpath('div/div/div[1]/p[1]/a/@title').extract()
item['url'] = sel.xpath('div/div/div[1]/p[1]/a/@href').extract()
print(item)
print('>'*50,'end')
API | 说明 |
---|---|
|
获取所有键值 |
|
获取所有键-值 |