使用Python从直接URL下载视频

我想用 python下载视频.我尝试使用youtube-dl,但不支持我想从中下载视频的网站.如何在 Python中下载视频.首先,我尝试在关注此链接 http://www.kmcgraphics.com/bits-of-code/how-to-get-the-direct-url-path-to-flv-video-files-on-youtube-for-free/之后获取我想从keepvid.com下载的视频的直接链接.我收到以下链接 http://www.animefun.com/dl/googDev.php?url=/108994262975881368074/Po270当我尝试运行以下代码时,我收到错误.

import urllib
test=urllib.URLopener()
test.retrieve("http://www.animefun.com/dl/googDev.php?url=/108994262975881368074/Po270.flv","testout.flv")

错误:

Traceback (most recent call last):
File "downl.py", line 14, in <module>
test.retrieve("http://www.animefun.com/dl/googDev.php?url=/108994262975881368074/Po270.flv","testout.flv")
File "/usr/lib/python2.7/urllib.py", line 240, in retrieve
fp = self.open(url, data)
File "/usr/lib/python2.7/urllib.py", line 208, in open
return getattr(self, name)(url)
File "/usr/lib/python2.7/urllib.py", line 359, in open_http
return self.http_error(url, fp, errcode, errmsg, headers)
File "/usr/lib/python2.7/urllib.py", line 376, in http_error
return self.http_error_default(url, fp, errcode, errmsg, headers)
File "/usr/lib/python2.7/urllib.py", line 381, in http_error_default
raise IOError, ('http error', errcode, errmsg, headers)
IOError: ('http error', 301, 'Moved Permanently', <httplib.HTTPMessage instance at 0x7f094d5d5290>)

我是Python的新手.所以请帮帮我.

urllib.URLopener默认不处理重定向

请改用urllib.FancyURLopener

import urllib
test=urllib.FancyURLopener()
test.retrieve("http://www.animefun.com/dl/googDev.php?url=/108994262975881368074/Po270.flv","testout.flv")
相关文章
相关标签/搜索