读取Excel中的视频文件地址+requests库下载后存入本地文件夹【多测师_王sir】

#coding=utf-8
"""
===========================
Author:多测师_王sir
Time:2020-07-27 16:27
Wechat:xiaoshubass
website:www.duoceshi.cn
===========================
"""

import re

class Util:

    @classmethod
    def read_excel(cls,num):
        data = xlrd.open_workbook('C:\project\dcs3\interface_auto\data.xlsx')
        table = data.sheet_by_name('sheet1')
        # 传入参数0就是第一列所有行  传入参数1就是第二列所有行
        return table.col_values(num)

    @classmethod
    def find_baona(cls):
        new = []
        for i in range(16):
            value =  cls.read_excel(0)[i] + cls.read_excel(1)[i]
            all = re.findall(u'宝娜宝娜+',value)
            for i in all:
                a = value.split(u'宝娜宝娜')
                del a[0]
                for i in a:
                    new.append(i)
        return new

    @classmethod
    def baonabaona(cls):
        '''
        寻找宝娜宝娜
        :return:
        '''
        for url in cls.find_baona():
            r = requests.get(url)
            filepath = r'C:\project\dcs3\interface_auto\01_baona'
            filename = filepath + '\\' + '0000' + str(cls.read_excel(1).index(url)) + 'baonabaona.wav'
            with open(filename, 'wb')as f:
                f.write(r.content)


if __name__ == '__main__':
    Util.baonabaona()

运行结果如下:
视频已经保存在本地文件夹里面了

 

 

posted @ 2020-07-27 22:19  多测师_树哥  阅读(276)  评论(0编辑  收藏  举报