思路与代码
鉴于 网易公开课 上的视频在线观看时无法加速,想要下载又必须得安装什么鬼客户端app之类的东西
遂使用 os.system,requests,配合 github 上大神写的 you-get 写了一个小脚本来自动下载视频到指定的目录
输入 课程首页的 url,输出目录 即可
import os
import requests
from lxml import html
from pprint import pprint
def cmd_download(url, filename):
info = os.system(r'you-get --debug -o C:\Users\rHotD\Downloads\wangyi_open\Linear_algebraic_exercises -O {} {}'.format(filename, url))
print(info)
return 1
# 课程首页 url
# 线性代数 url
response = requests.get('http://open.163.com/special/opencourse/daishu.html')
# 线性代数习题 url
response = requests.get('http://open.163.com/special/opencourse/mitxianxingdaishuxitike.html')
tree = html.fromstring(response.text)
url_list = tree.xpath('//div[@class="m-mn"]//table[2]//tr/td[1]/a//@href')
filename_list = tree.xpath('//div[@class="m-mn"]//table[2]//tr/td[1]/a/text()')
filename_list = list(map(lambda x:x.strip(), filename_list))
pprint(filename_list)
# url_list = ['http://open.163.com/movie/2010/11/7/3/M6V0BQC4M_M6V29E773.html', 'http://open.163.com/movie/2010/11/P/P/M6V0BQC4M_M6V29EGPP.html', 'http://open.163.com/movie/2010/11/H/O/M6V0BQC4M_M6V29FCHO.html', 'http://open.163.com/movie/2010/11/3/S/M6V0BQC4M_M6V29F33S.html', 'http://open.163.com/movie/2010/11/J/K/M6V0BQC4M_M6V29FRJK.html', 'http://open.163.com/movie/2010/11/B/5/M6V0BQC4M_M6V2AB1B5.html', 'http://open.163.com/movie/2010/11/H/H/M6V0BQC4M_M6V2ABAHH.html', 'http://open.163.com/movie/2010/11/V/8/M6V0BQC4M_M6V2ABHV8.html', 'http://open.163.com/movie/2010/11/C/T/M6V0BQC4M_M6V2ACDCT.html', 'http://open.163.com/movie/2010/11/D/T/M6V0BQC4M_M6V2ADFDT.html', 'http://open.163.com/movie/2010/11/2/T/M6V0BQC4M_M6V2AJS2T.html', <