youtube 的 Python urllib 基本脚本

标签 python youtube urllib

我正在尝试从 Youtube 下载视频,并尝试了以下方法:

url = "http://www.youtube.com/watch?v=f4l3pBovB_c"
urllib.urlretrieve(url,"test.mp4")

它创建文件 test.mp4,但出现以下错误:

Windows media player cannot play the file. The Player might not support the file type or might not support the codec that was used to compress the file.



我想尝试自己了解如何完成此操作,我已经看过 youtube-dl.py 之类的模块,但再次希望以最简单的形式使代码工作,以便我可以在构建脚本时理解它。

最佳答案

Youtube 视频不存储在 youtube.com域,因此您尝试下载的视频不存在该 URL。下载 youtube 视频是一个复杂的过程,但您可以使用 youtube-dl为了它。

关于youtube 的 Python urllib 基本脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15060186/

相关文章:

python - 如何在 Scikit-learn 中获取 OneHotEncoder 的维度数

ios - iOS URL方案可以在相应的应用程序中打开特定的youtube和soundcloud页面?

python - Urllib 的 urlopen 在某些站点上中断(例如 StackApps api): returns garbage results

c# - 在C#中从Youtube读取ajax响应

youtube - 如何查询YouTube API,以从自动生成的 'Topic' channel 获取视频?

python - 查看标签之间的 html 文本(python、lxml、urllib、xpath)

python - 属性错误 : module 'urllib' has no attribute 'parse'

python - 为什么 dict_items 对象不支持索引?

python - 如何在 NumPy 中一次乘以 3 个以上的向量

python - ax.scatter() 语法无效?