【问题标题】:PyTube error: pytube.exceptions.RegexMatchError: regex_search: could not find match for (?:v=|\/)([0-9A-Za-z_-]{11}).*PyTube 错误:pytube.exceptions.RegexMatchError:regex_search:找不到匹配项 (?:v=|\\/)([0-9A-Za-z_-]{11})。*
【发布时间】:2022-08-15 19:29:54
【问题描述】:

这是我使用 python tkinter 下载 YouTube 视频的代码,它工作正常,但在插入 def ytVidDownloader() 后,它不起作用(插入 def,因为它是我项目的模块)

(缩短两个程序以便更好地理解)

主仪表板文件是

from tkinter import *
import moduleYVD
window= Tk()
window.geometry(\"750x600\")
Button(window, text = \"YouTube Video Downloader\", command = moduleYVD.ytVidDownloader).pack(pady=18)
window.mainloop()

ModuleYVD 是:

from tkinter import *
from pytube import YouTube

def ytVidDownloader():
   root = Tk()
   root.geometry(\'500x300\')
   link = StringVar()
   link_enter = Entry(root, width = 70,textvariable = link).place(x = 32, y = 130)
   def Downloader():                #function to download video
      url =YouTube(str(link.get()))
      video = url.streams.first()
      video.download()
      Label(root, text = \'DOWNLOADED\', font = \'arial 15\').place(x= 180 , y = 210)

   Button(root,text = \'DOWNLOAD\', font = \'arial 15 bold\' , padx = 2, command = Downloader).place(x=80 ,y = 190)
   root.mainloop()

我得到的错误是:

    Exception in Tkinter callback
Traceback (most recent call last):
  File \"C:\\Users\\kiran\\AppData\\Local\\Programs\\Python\\Python310\\lib\\tkinter\\__init__.py\", line 1921, in __call__
    return self.func(*args)
  File \"c:\\Users\\kiran\\AppData\\Local\\Programs\\Python\\Python310\\Project ToolKit\\moduleYVD.py\", line 34, in Downloader
    #function to download video
  File \"C:\\Users\\kiran\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\pytube\\__main__.py\", line 71, in __init__
    self.video_id = extract.video_id(url)
  File \"C:\\Users\\kiran\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\pytube\\extract.py\", line 133, in video_id
    return regex_search(r\"(?:v=|\\/)([0-9A-Za-z_-]{11}).*\", url, group=1)
  File \"C:\\Users\\kiran\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\pytube\\helpers.py\", line 129, in regex_search
    raise RegexMatchError(caller=\"regex_search\", pattern=pattern)
pytube.exceptions.RegexMatchError: regex_search: could not find match for (?:v=|\\/)([0-9A-Za-z_-]{11}).*

我该如何解决这个错误?

  • 热烈欢迎SO。请阅读stackoverflow.com/help/how-to-ask 并更新您的问题。你必须帮助我们来帮助你。
  • 正则表达式无法匹配字符串,但没有字符串,没有人能说出它失败的原因,也不知道如何更正。

标签: python regex tkinter pytube


【解决方案1】:

我得到了我自己的问题的答案。 我的代码中的问题是我只导入了YouTube from pytube 而不是整个pytube 库。所以,我只单独导入pytube, 和另一个from pytube import YouTube,并且代码有效。

【讨论】:

    猜你喜欢
    • 2023-01-10
    • 2021-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多