Download 163 video

本文介绍了一个使用Python编写的简单网易视频课程下载器。该下载器利用BeautifulSoup解析网页,通过wget下载视频文件。它首先从课程页面抓取课程列表,然后针对每个课程下载对应的FLV视频文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#coding:gbk

import os, sys, urllib
from BeautifulSoup import BeautifulSoup

true = True
false = False
null = None

def output(str):
    """
    输出调试信息
    """
    print str

def download_file(url, filename):
    print url
    print filename

    output('download %s, save to %s ...' % (url, filename))
    if (os.path.exists(filename)):
        return 0
    cmd = 'wget -O %s %s' % (filename, url)
    output(cmd.encode('gbk'))
    return os.system(cmd.encode('gbk'))

def download_course(url, number, title):   
    course_id = url[url.rfind('/')+1:].split('.')[0]
    dirletters = course_id[-2:]   
    xmlurl = 'http://live.ws.126.net/movie/%s/%s/2_%s.xml' % (dirletters[0], dirletters[1], course_id)   
    #output(xmlurl)
    content = urllib.urlopen(xmlurl).read()
    soup = BeautifulSoup(content)
    flvurl = soup.find('flv').text   
    download_file(flvurl, '%s_%s.flv' % (str(number).rjust(3,'0'), title))       
    return

def download_163v_video(url):
    content = urllib.urlopen(url).read()
    soup = BeautifulSoup(content)
    items = soup.findAll('li', {'class':'odd_li'})
    courses = [(item.a['href'], item.h3.a.text) for item in items]
    index = 0
    for (url, title) in courses:
        index += 1
        download_course(url, index, title)
    return

if __name__ == '__main__':
    download_163v_video(sys.argv[1])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值