Pytube RegexMatchError

时间:2018-09-05 17:38:14

标签: python-2.7 youtube pytube

我试图用python编写脚本,在该脚本中,提示用户在命令行上输入youtube链接。然后应下载此链接

from pytube import YouTube

downloadFile = raw_input("Enter your Youtube link: ")
YouTube(downloadFile).streams.first().download()

但是,当在命令行上输入链接时,我得到以下信息:

File "dl.py", line 10, in <module>
    YouTube(downloadFile).streams.first().download()
  File "build/bdist.linux-x86_64/egg/pytube/__main__.py", line 69, in __init__
  File "build/bdist.linux-x86_64/egg/pytube/extract.py", line 43, in video_id
  File "build/bdist.linux-x86_64/egg/pytube/helpers.py", line 39, in regex_search
pytube.exceptions.RegexMatchError: regex pattern ((?:v=|\/)([0-9A-Za-z_-]{11}).*) had zero matches

我能够通过python interpeter使其工作。

欢迎提出任何建议!

1 个答案:

答案 0 :(得分:0)

好吧,经过一番扎根之后,似乎可以解决问题

import sys # import sys 
import pytube

link = raw_input('Please enter a url link\n')
yt = pytube.YouTube(link)
stream = yt.streams.first()
finished = stream.download()
print 'Download is complete'

sys.exit()