给定网址,如何验证网址是否指向可下载视频?
鉴于这种情况,函数is_downloadable_video(url)
的实现是什么:
downloadable_video_url = 'https://pixabay.com/en/videos/download/video-8579_large.mp4?attachment'
not_downloadable_url = 'http://techslides.com/demos/sample-videos/small.mp4'
is_downloadable_video(downloadable_video_url) # Returns True
is_downloadable_video(not_downloadable_url) # Returns False
答案 0 :(得分:1)
这会检查有效的html
:
import requests
urls = ['https://pixabay.com/en/videos/download/video-8579_large.mp4?attachment',
'http://techslides.com/demos/sample-videos/small.mp4']
for url in urls:
r = requests.head(url)
print "text/html" in r.headers["content-type"]
在我看来,这会检查是否可下载:
for url in urls:
print 'download=1' in ''.join(requests.head(url).headers.values())