gpt4 book ai didi

python - Pytube 库 - 尝试访问视频数据时收到 "pytube.exceptions.RegexMatchError: regex pattern"错误

转载 作者:行者123 更新时间:2023-12-01 01:18:55 24 4
gpt4 key购买 nike

当尝试使用 pytube API 库访问 Youtube 视频的“标题”等数据时,我收到以下错误

pytube.exceptions.RegexMatchError: regex pattern (yt.akamaized.net/)\s*\|\|\s*.?\sc\s*&&\sd.set([^,]+\s,\s*(?P[a-zA-Z0-9$]+)() had zero matches

这是我正在使用的代码,它提供了上述错误。

import sys  
import pytube

link = input('Enter url: ') # url is: https://www.youtube.com/watch?v=KSbj-cFtFPA
yt = pytube.YouTube(link)
print(yt.title)

sys.exit()

有人知道如何解决这个错误吗?我已经进行了一些在线搜索,提供的答案并不明确,并且当我尝试时不起作用。

注意:我尝试卸载 pytube 并重新安装它,但这并没有解决问题。

最佳答案

pytube 中存在错误,因此请使用此命令重新安装它。

pip install git+https://github.com/nficano/pytube.git

#####################################################

import sys
import pytube

link = input('Enter url: ') # url is: https://www.youtube.com/watch?v=KSbjcFtFPA
yt = pytube.YouTube(link)
print(yt.title)

**OUTPUT** Sanford and Son S02E02

sys.exit()

以下是有关此错误的一些附加信息:https://github.com/nficano/pytube/issues/333

这是对该问题的后续答复。我根据文档添加了一些错误处理来告诉您发生了什么。

- Video 1 in the list will throw an extraction error. because the video has been removed from YouTube

- Video 2 in the list will throw an unavailable error. because the video does not exist on YouTube

- Video 3 in the list will display the correct title info, because the video exists on YouTube.

video_lists = ['https://www.youtube.com/watch?v=KSbjcFtFPA',
'https://www.youtube.com/watch?v=MEEJOZkmIxvU',
'https://www.youtube.com/watch?v=MEEJOZkmIxU'
]

for video in video_lists:

try:
yt = pytube.YouTube(video)
print (yt.title)

#################################################################
# This one should catch - pytube.exceptions.RegexMatchError:
# regex pattern ((?:v=|\/)([0-9A-Za-z_-]{11}).*) had zero matches
#################################################################
except pytube.exceptions.RegexMatchError:
print('The Regex pattern did not return any matches for the video: {}'.format(video))

except pytube.exceptions.ExtractError:
print ('An extraction error occurred for the video: {}'.format(video))

except pytube.exceptions.VideoUnavailable:
print('The following video is unavailable: {}'.format(video))

**OUTPUTS**
An extraction occurred for the video: https://www.youtube.com/watch?v=KSbjcFtFPA

The following video is unavailable: https://www.youtube.com/watch?v=MEEJOZkmIxvU

Love of my life & Bohemian Rhapsody - 1080 HD

特别说明

相关错误已链接到 pytube 的 cipher.py 文件。请检查此文件以确保下面的代码部分与您的代码部分匹配:

def get_initial_function_name(js):
"""Extract the name of the function responsible for computing the signature.

:param str js:
The contents of the base.js asset file.

"""
# c&&d.set("signature", EE(c));
pattern = r'\bc\s*&&\s*d\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\('
logger.debug('finding initial function name')
return regex_search(pattern, js, group=1)

关于python - Pytube 库 - 尝试访问视频数据时收到 "pytube.exceptions.RegexMatchError: regex pattern"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54028675/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com