EXE下载地址链接:http://pan.baidu.com/s/1miOfnuw 密码:dk3i

使用方法:

双击打开exe,然后按照TIPS操作即可。

打不开的百度命令行程序如何运行,或者查看评论回复

点击一门课程,比如:http://study.163.com/course/courseMain.htm?courseId=320022

看到url,上面的320022就是courseId了。

写脚本花了几十分钟,搞web花了一下午。。。

Github地址

觉得有用的帮忙在gayhub点颗星星~感谢!

 

import requests
import re
import sys
import getopt

opts, args = getopt.getopt(sys.argv[1:], '-h-g-d:-n:', ['help','generate', 'dir=', 'name='])

def GetInfo(Vid):
    print("正在获取课程信息...")
    data={'callCount':1,
    'scriptSessionId':'${scriptSessionId}190',
    'c0-scriptName':'PlanNewBean',
    'c0-methodName':'getPlanCourseDetail',
    'c0-id':'0',
    'c0-param0':'string:'+Vid,
    'c0-param1':'number:0',
    'c0-param2':'null:null',
    'batchId':"1506324769538"}

    html=requests.post('http://study.163.com/dwr/call/plaincall/PlanNewBean.getPlanCourseDetail.dwr?1506324769538',data=data,headers=headers)

    #s16.lessonName="\u8BBE\u7F6E\u5750\u6807\u8F741";s16.leve
    LessonName=re.findall(r's\w*?\.id=(.*?);.*?s(\w*?)\.lessonName="(.*?)";',html.text)

    return LessonName



def GetVideoUrl(LessonName, Vid):
    print("正在获取课件信息:")
    Lists = []
    for i in range(0,len(LessonName)):

        Vnum =  LessonName[i][0]
        VName = LessonName[i][2].encode('utf-8').decode('unicode_escape','ignore')
        print(VName)

        data={'callCount':'1',
        'scriptSessionId':'${scriptSessionId}190',
        'c0-scriptName':'LessonLearnBean',
        'c0-methodName':'getVideoLearnInfo',
        'c0-id':'0',
        'c0-param0':'string:'+ Vnum,
        'c0-param1':'string:'+ Vid,
        'batchId':'1506324769538'}

        video=requests.post("http://study.163.com/dwr/call/plaincall/LessonLearnBean.getVideoLearnInfo.dwr?1506327358812",data=data,headers=headers)
        try:
            Vurl = re.findall(r'flvHdUrl="(.*?)"',video.text)[0]
        except:
            pass
        Value = [VName,Vurl]
        Lists.append(Value)
    return Lists

def MakeTxt(Lists):
    print("正在生成视频地址...")
    AllLinks = ""

    for i in range(0,len(Lists)):
        Lists[i][1] = Lists[i][1].replace("http://","http://219.138.29.26/")
        Links = '<div class="down"><a href="'+Lists[i][1]+'">'+Lists[i][0]+'</a></div>'+"\n"
        AllLinks = AllLinks + Links
    filename = Vid+".html"
    with open(filename,'w',encoding='utf-8') as f:
        f.write("""
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>视频下载页面</title>
    <link rel="stylesheet" type="text/css" href="http://www.lz1y.cn/css/download.css">
</head>
<body>
<div class="download">
    <div class="head">
    <div class="logo"><img src="http://www.lz1y.cn/wordpress/wp-content/uploads/2017/06/[email protected]_0e_1l-180x180.png" alt="logo"></div>
    <div class="logo-title">网易云课堂视频下载 <br /> Author: Lz1y</div>
    </div><br/><br/><br/><br/><br/><br/><br/>
        <div class="down-column">
    <div class="down1"><a href="">课程下载</a></div>
    """+AllLinks+"""
    </div>
    <div class="foot"><p><a href="http://www.lz1y.cn/wordpress" target="_blank"><font color="black">Lz1y'Blog | Coding My world</a></p>
    </div>
</div>
</body>
</html>
    """)

def MakeHtml(Lists):
    print(Lists[i][1])
    AllLinks = ""

    filename = Vid + "_name.txt"
    for i in range(0,len(Lists)):
        Links = '<div class ="down"><font color="black"><a href="'+Lists[i][1]+'"> '+Lists[i][0]+' </font></a></div>'
        AllLinks = AllLinks + Links

        with open(filename,'a',encoding='utf-8') as f:
            f.write(Lists[i][0])

    html = """
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>视频下载页面</title>
    <link rel="stylesheet" type="text/css" href="http://www.lz1y.cn/css/download.css">
</head>
<body>
<div class="app-download">
    <div class="logo"><img src="//www.lz1y.cn/wordpress/wp-content/uploads/2017/06/[email protected]_0e_1l-180x180.png" alt="logo"></div>
    <div class="logo-title">网易云课堂视频下载 <br /> Author: Lz1y</div><br>"""+AllLinks+"""
    <br><p><a href="http://www.lz1y.cn/wordpress" target="_blank"><font color="black">Lz1y'Blog | Coding My world</a></p>
</div>
</body>
</html>
    """
    filename = Vid+".html"
    with open(filename,'w',encoding='utf-8') as f:
        f.write(html)

if __name__ == "__main__":
    headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0"}
    print("网易云课堂视频下载工具 V1.2 beta1")
    print("Author:Lz1y")
    print("Blog:http://www.lz1y.cn/wordpress/")
    print("\033[0;31mTips:如何获取CourseId")
    print("         example:一个课程的网址是 http://study.163.com/course/introduction.htm?courseId=320022")
    print("         320022就是CourseId,输入到下方即可\033[0m!")
    
    Vid = input("\n请输入CourseId:\n")
    LessonName = GetInfo(Vid)
    Lists = GetVideoUrl(LessonName, Vid)
    MakeTxt(Lists)
"""
    for opt_name, opt_value in opts:
        if opt_name in ('-d', '--dir'):
            dir = opt_value

        if opt_name in ('-n', '--name'):
            name = opt_value
            with open(name,'w',encoding='utf-8') as f:
                names = f.readlines()
            files = os.listdir(dir)
            for i in range(0,len(files)):
                os.rename(dir+"/"+files[i],dir+"/"+names[i])


        if opt_name in ('-g','--generate'):
            headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0"}

            Vid = input("请输入CourseId:\n")
            LessonName = GetInfo(Vid)
            Lists = GetVideoUrl(LessonName, Vid)
            MakeTxt(Lists)

        if opt_name in ('-h', '--help'):
            print("-g --generate   生成web页面")
            



    #    MakeHtml(Lists)
"""

 



本文链接地址: 网易云课堂电脑端下载视频小工具~

原创文章,转载请注明: 转载自Lz1y's Blog

85 thoughts on “网易云课堂电脑端下载视频小工具~

      1. html文件将在CMD的路径中生成。你也可以先打开cmd,然后执行cd C:,将cmd的目录改动为c盘根目录

  1. 感谢无私分享,我在win10下确实也遇到了同样的情况,按照你的评论已经解决。建议在本文开头把win10这种情况备注上去,避免后来人走弯路。另外,也备注上:在getvideo所在目录会生成一个含有全部下载链接的HTML文件。

    1. 因为是自己打包成的.exe可执行文件,没加壳什么的,就像一个没身份的人,杀毒软件会直接杀掉的,退出杀毒的就行了。

  2. 昨晚刚看到,亲试发现没问题,今天一早就发现下不了啦,都链接不到资源的。难道是网易有看到了你的博?哈哈哈哈

  3. 您好,这篇文章很有帮助。我想问一下MOOC的课程有没有类似的下载的方法,比如这个。http://mooc.study.163.com/learn/1000002014?tid=2001332007
    知乎上那个用脚本的下载方法实在是没搞懂,所以特地来请教一下,打扰了。另外,您说联系方式博客里有,我找了一圈,又进行了搜索,还是没找到邮箱,所以只好发在评论里,请见谅。(可能是我太笨了。。。)

    1. 不好意思,博客重装了一次,所以之前的联系方式也消失了。慕课的和网易云的不是同一个原理。周末抽个时间我再写一个脚本,知乎上开个文章发一下吧~现在有别的事情正在做~

    1. 谢谢博主,收费视频已经可以下载了,我觉得应该是要在Python环境中应该没问题。对了,但是那个一键下载不能用。

      1. 解决了,非常感谢分享!另外迅雷下载所有的是一串数字,都不知哪个视频对应哪个课程,这个还能优化吗?

          1. 用楼主的程序迅雷下载完视频之后,运行链接的rename.py时,在第28行报错。KeError:‘1003907006.html’。这个啥原因??

  4. 感谢博主的软件,有个问题希望能看一下courseId=1003122015这个课程第一课似乎是个图片,然后软件就报错了,希望你能帮助解决一下,万分感谢。
    请输入CourseId:
    1003122015
    正在获取课程信息…
    正在获取课件信息:
    第一卷课程地址点击:“参考资料”即可跳转
    Traceback (most recent call last):
    File “GetVideo.py”, line 137, in
    File “GetVideo.py”, line 52, in GetVideoUrl
    UnboundLocalError: local variable ‘Vurl’ referenced before assignment
    Failed to execute script GetVideo

    1. 手机端也可以下载,我只是省掉了从手机拖到硬盘中的过程而已。再说我没有盈利,也没有传播,只是交流代码学习。

  5. 请输入CourseId:
    320022
    正在获取课程信息…
    正在获取课件信息:
    Django初步-安装
    Traceback (most recent call last):
    File “GetVideo.py”, line 137, in
    File “GetVideo.py”, line 52, in GetVideoUrl
    UnboundLocalError: local variable ‘Vurl’ referenced before assignment
    Failed to execute script GetVideo

    请问为什么会这样报错呢?

  6. 请输入CourseId:
    320022
    正在获取课程信息…
    正在获取课件信息:
    Django初步-安装
    Traceback (most recent call last):
    File “GetVideo.py”, line 137, in
    File “GetVideo.py”, line 52, in GetVideoUrl
    UnboundLocalError: local variable ‘Vurl’ referenced before assignment
    Failed to execute script GetVideo

    请问为什么会这样报错呢?下载免费课程就会这样

  7. 请输入CourseId:
    1003862031
    正在获取课程信息…
    正在获取课件信息:
    项目简介
    Traceback (most recent call last):
    File “GetVideo.py”, line 137, in
    File “GetVideo.py”, line 52, in GetVideoUrl
    UnboundLocalError: local variable ‘Vurl’ referenced before assignment
    Failed to execute script GetVideo

    C:\Users\Administrator>

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.