python抓取在線視頻

#coding:UTF-8
import urllib2
import os
import winsound

def save(string):
    i=0
    while True:
        index = str(i).zfill(6)+'.ts' #補0
        try: #不知道有多少ts文件,若存取失敗則說明完成
            url = 'http://vedio.leiphone.com/nfzWoRbIRB5rXxvcvYjdCdLaKCU=/'+string+'/'+index
            f = urllib2.urlopen(url)
            with open(index,'wb') as code:
                code.write(f.read())
        except:
            print 'Ok'
            break
        i = i+1
def trans(name):
    cmd = 'copy /b *.ts '+name+'.mp4'#合併ts爲一個mp4 
    os.system(cmd)
    os.system('del *.ts')#刪除所有ts
if __name__ == '__main__':
    while True:
        string= raw_input('coding:')
        name =raw_input('name:')
        save(string)
        trans(name)
        winsound.Beep(600,1000) #時間有點長,設置結束提醒

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章