码迷,mamicode.com
首页 > 编程语言 > 详细

python扒取c++视频示例

时间:2015-04-20 11:15:57      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:python   c++   视频   

#!/usr/bin/pytyon
# -*- coding:utf-8 -*-
import re
import urllib

vurl = 'http://www.enet.com.cn/eschool/video/c++/'
domain = 'http://www.enet.com.cn'

def getVideoList(vurl):

    #find all c++ url
    html = urllib.urlopen(vurl).read()
    reg = r'href="(/eschool/video/autohtml/310/.*?.shtml)".*>(.*?)<\/a>'
    videoRe = re.compile(reg)
    videoList = re.findall(videoRe, html)
    

    videoListCount = len(videoList)
    x = 0

    # iteration c++ url
    for urlInfo in videoList:
        
        url = urlInfo[0]
        # find real c++ url
        url = domain+url
        html = urllib.urlopen(url).read()
        reg = r'(http:\/\/images\.enet\.com\.cn\/eschool\/c\+\+\/.*?\.swf)'
        videoRe = re.compile(reg)
        swfUrl = re.findall(videoRe, html)
        #print swfUrl

        # name
        reg = r'c\+\+\/(.*?)\/.*?\.swf'
        videoRe = re.compile(reg)
        videoName = re.findall(videoRe, swfUrl[0])[0].replace('/','_')+'_'+urlInfo[1].replace(':','').replace(' ','_').replace('.','_')+'.swf'
        urllib.urlretrieve(swfUrl[0], videoName)
        
        x = x + 1
        ratio = x*100/videoListCount
        print videoName,' to -->  ',x,'  ==>  ',videoListCount
        print '[','#'*ratio,' '*(100-ratio),']  ',ratio,'%'
        #exit()
    else:
        print 'endding!!'
    
getVideoList(vurl)

python扒取c++视频示例

标签:python   c++   视频   

原文地址:http://blog.csdn.net/fb408487792/article/details/45147131

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!