我正在尝试使用pytube 库下载我在 .csv 文件上的一堆链接。
编辑:
工作代码:
import sys
reload(sys)
sys.setdefaultencoding('Cp1252')
import os.path
from pytube import YouTube
from pprint import pprint
import csv
with open('onedialectic.csv', 'rb') as f:
reader = csv.reader(f)
for row in reader:
try:
yt = YouTube(row[1])
path = os.path.join('/videos/',row[0])
path2 = os.path.join(path + '.mp4')
print(path2)
if not os.path.exists(path2) :
print(row[0] + '\n')
pprint(yt.get_videos())
yt.set_filename(row[0])
video = yt.get('mp4', '360p')
video.download('/videos')
except Exception as e:
print("Passing on exception %s", e)
continue