编程语言
首页 > 编程语言> > python 下载豆瓣上一个小电影预告片

python 下载豆瓣上一个小电影预告片

作者:互联网

 

#coding=utf-8

import sys
import  io 
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

import requests
from bs4 import BeautifulSoup

from tqdm import tqdm


def get_video_url():
    url = "https://movie.douban.com/trailer/243698/#content"
    
    req0 = requests.get(url)
    soup0 = BeautifulSoup(req0.text,'lxml')
    item_vd = soup0.find("video")
    video_url = item_vd.source['src']
    return video_url

def download_vd(vd_url,i):
    from contextlib import closing
    with closing(requests.get(vd_url,stream = True)) as resp, open("test_"+str(i)+".mp4",'wb') as f:
        for chunk in  tqdm(resp.iter_content(128)):
            f.write(chunk)

def main():
    vd_url = get_video_url()
    download_vd(vd_url,0)
    
if __name__ == "__main__":
    main()

标签:__,vd,get,python,url,豆瓣,video,预告片,import
来源: https://blog.csdn.net/xuyinxin/article/details/91305903