【问题标题】:Download all mp4 videos from a website从网站下载所有 mp4 视频
【发布时间】:2018-07-07 11:29:49
【问题描述】:

This是我要下载的讲座链接。单击每个链接然后下载是很烦人的。我想从网站下载所有 mp4 文件。如何实现它。我已经搜索了足够长的时间来在这里提问。我已经下载了 Winwget,但我无法弄清楚如何下载具有 .mp4 扩展名的文件。我对任何操作系统 windows 10 或 ubuntu 解决方案都很满意。

【问题讨论】:

标签: linux windows download wget


【解决方案1】:

对于某些网站,您可以使用youtube-dl python 脚本。

  1. 打开 cmd 提示符
  2. 在那里输入 pip install youtube-dl
  3. 在cmd中编写python脚本如下:

    C:\Users\user_name>youtube-dl 链接

如果是需要登录的网站,比如Udemy,写

 C:\Users\user_name>youtube-dl -u user@gmail.com -p password course_link

【讨论】:

    【解决方案2】:

    如果您可以使用 Python,这里有一个解决方案。它获取视频不同链接的内容并将其存储在“video_X.mp4”下,X在1到42之间:

    import requests
    
    
    for x in xrange(1,43):
        video_url = "http://nptel.ac.in/courses/download_mp4.php?subjectId=111105035&filename=mod01lec" + str(x).zfill(2)  + ".mp4"
        with open('video_' + str(x).zfill(2) + '.mp4', 'wb') as handler:
            handler.write(requests.get(video_url).content)
        pass
    

    【讨论】:

    • 这个脚本在哪里下载文件?
    • 它正在下载您正在执行python脚本的文件夹中的文件
    【解决方案3】:

    我使用以下答案 (https://stackoverflow.com/a/40553400/11786575) 来编写我的 Python 代码:

    import urllib.request
    
    ### First, get a page source from Chrome inspector (press F12, select, copy and paste from "Elements"), paste the whole text here. The text should include a lot of text and also links to the mp4 video files.
    
    filename = 'C:\\file_location...\\...\\...\\page_source_f12.txt'
    
    ### Write everything from the previous text file that includes .mp4 to a list
    list_1 = []
    with open(filename, "r", encoding='utf-8') as myFile:
        lines = myFile.readlines()
        for line in lines:
            if ".mp4" in line:
                a = ((str(line)).lstrip()) ### and possibly other data modification to remove "href" etc. from the text lines
                print(a)
                list_1.append(a)
    
    ### Use the list to write a new file including only the video links
    with open('C:\\...\\video_links.txt', 'w+', encoding='utf-8') as myFile2:
        for i in list_1:
            myFile2.write(str(i) + "\n")
    
    ### Use urllib.request to download every video file from the links in your list
    counter = 0
    for url_link in list_1:
        if "https" in url_link:
            print(url_link)
            urllib.request.urlretrieve(url_link, "video" + str(counter) + ".mp4")
            print("------NOW DOWNLOADED: video" + str(counter) + ".mp4------")
            counter += 1
    print("*****COMPLETE******")
    
    # If you are using vscode, the videos are downloaded to the folder where you run the code in (the fila path shown in the terminal)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-11
      • 1970-01-01
      • 1970-01-01
      • 2012-08-02
      • 2018-09-28
      • 2017-03-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多