首页 > 编程语言 > 详细

python扒取c++视频示例

时间:2015-04-20 11:13:09      阅读:306      评论:0      收藏:0      [点我收藏+]
#!/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++视频示例

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!