# -*- coding: utf-8 -*-
import requests
from lxml import etree
#通过xhr未找到json,故用原始页下载
class Spider(object):
    def starr_request(self):
        for i in range(1,223):
            response=requests.get('https://ibaotu.com/shipin/7-0-0-0-0-{}.html'.format(i))
            html=etree.HTML(response.content.decode())
            self.xpath_data(html)

    def xpath_data(self,html):
        src_list=html.xpath('//div[@class="video-play"]/video/@src')
        tit_list=html.xpath('//span[@class="video-title"]/text()')
        #使二者一一对应
        for src,tit in zip(src_list,tit_list):
            print(src,tit)
            url='http:'+src
            name=tit+'.mp4'
            response=requests.get(url)
            print('down'+name)
            with open('video/{}'.format(name),'wb') as f:
                f.write(response.content)

if __name__ =='__main__':
    spider=Spider()
    spider.starr_request()