视频爬取

一、爬取视频

import re
import requests
"""
@author RansySun
@create 2019-07-22-12:05
"""

response = requests.get('http://www.mod.gov.cn/v/index.htm')
data = response.text
# <a href="2019-06/27/content_4844619.htm" class="img"><img src="attachement/jpg/site21/20190627/309c237042ea1e7f205317.jpg" border="0" width="100%"><div class="text"><em class="video_50x50"></em><h3>2019年6月国防部例行记者会实况</h3><small>2019-06-27</small></div></a>

res_data = re.findall('<a href="(.*?)" class="img">', data)
for res in res_data:
    res = "http://www.mod.gov.cn/v/"+res
    video_response = requests.get(res)
    print(res)
    video_data = video_response.text

    # http://vv.chinamil.com.cn/asset/category3/2019/06/27/asset_357593.mp4

    video_res = re.findall('//Video (.*?.mp4)', video_data)[0]

    print(video_res)
    mp4_response = requests.get(video_res)
    mp4_data = mp4_response.content
    mp4_name = video_res.split("/")[-1]
    fw = open(mp4_name, 'wb')
    fw.write(mp4_data)
    print("成功")

posted @ 2019-07-23 15:06  RandySun  阅读(693)  评论(0编辑  收藏  举报