python从网站下载视频而不知道文件名 [英] python download video from website without knowing file name

查看:282
本文介绍了python从网站下载视频而不知道文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何从网站下载视频。

i am wondering how it is possible to download a video from a website.

import urllib
testfile = urllib.URLopener()
testfile.retrieve("http://randomsite.com/file.gz", "file.gz")

我明白,只要你有文件扩展名,上述脚本就可以下载一个文件。
我想知道的是,如何下载文件,而不知道它的扩展名?
我如何制作一个通过插入视频网址下载视频的程序例如当您右键单击并复制视频网址

I understand that the above script is able to download a file as long as you have the file extension. What i am wondering is how do i download a file without knowing it's extension? How do i make a program that will download a video via inserting the videos url "Such as when you right click and copy video url"

如果有人可以指向正确的方向,将不胜感激!

If someone could point me in the right direction that would be appreciated !

推荐答案

from __future__ import unicode_literals
import youtube_dl

ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['YOUR URL'])

我可以使用以上代码从无YouTube网站下载视频:)

I was able to download videos from a none youtube site with the above code :)

这篇关于python从网站下载视频而不知道文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆