# -*- coding: utf-8 -*-
import scrapy
from scrapy.spiders import Spider
from scrapy.selector import Selector
from doubanMovie.items import DoubanmovieItem

class movieSpider(Spider):
    name = 'movie'
    allowed_domains = ['douban.com']
    start_urls = ['https://movie.douban.com/top250']
    for i in range(1,10):
        start_urls.append("https://movie.douban.com/top250?start=%d&filter="%(25*i))

    def parse(self, response):
        item=DoubanmovieItem()
        sel=Selector(response)
        imgs=sel.xpath('//*[@id="content"]/div/div[1]/ol/li')
        item['url']=[]
        item['name']=[]
        for img in imgs:
            site=img.xpath('div/div[1]/a/img/@src').extract_first()
            img_name=img.xpath('div/div[1]/a/img/@alt').extract_first()
            item['url'].append(site)
            item['name'].append(img_name)
            yield item