有没有办法用python从网页下载视频? [英] Is there a way to download a video from a webpage with python?

查看:49
本文介绍了有没有办法用python从网页下载视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从这个网站上提取视频.http://www.jpopsuki.tv/video/Meisa-Kuroki---坏女孩/eec457785fba1b9bb35481f438cf35a7

I would like to pull the video from this website. http://www.jpopsuki.tv/video/Meisa-Kuroki---Bad-Girl/eec457785fba1b9bb35481f438cf35a7

我可以用python访问它并获取整个html.但是视频的 url 是相对的,即看起来像这样:<source src="/images/media/eec457785fba1b9bb35481f438cf35a7_1351466328.mp4" type="video/mp4"/>

I can access it with python and get the whole html. But the video's url is relative, i.e. looks like so: <source src="/images/media/eec457785fba1b9bb35481f438cf35a7_1351466328.mp4" type="video/mp4" />

有没有办法使用python从网站上提取它?

Is there a way to pull it from the website using python?

推荐答案

找到下面的函数 这里

我认为这会做到:

import requests

def download_file(url):
    local_filename = url.split('/')[-1]
    # NOTE the stream=True parameter
    r = requests.get(url, stream=True)
    with open(local_filename, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024): 
            if chunk: # filter out keep-alive new chunks
                f.write(chunk)
                #f.flush() commented by recommendation from J.F.Sebastian
    return local_filename

download_file("http://www.jpopsuki.tv/images/media/eec457785fba1b9bb35481f438cf35a7_1351466328.mp4")

这篇关于有没有办法用python从网页下载视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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