里面很多免费的视频,因为习惯了看技术视频按2倍速度看,所以就下载下来看
#coding=utf-8
import re,urllib2,urllib,json,time,os
def getHtmlCode(url):
request = urllib2.Request(url)
request.add_header('X-Session','xxx')
response = urllib2.urlopen(request,timeout=30)
return response.read()
def getVideo():
for i in range(1,10000):
print 'id---' + str(i)
url = 'http://m.quzhiboapp.com/api/lives/' + str(i)
htmlCode = getHtmlCode(url)
decodeJson = json.loads(htmlCode)
result = decodeJson["result"]
subject = ''
beginTs = ''
videoUrl = ''
coursewareUrl = ''
if result.has_key('subject'):
subject = result["subject"]
if result.has_key('beginTs'):
beginTs = result["beginTs"]
if result.has_key('videoUrl'):
videoUrl = result["videoUrl"]
if result.has_key('coursewareUrl'):
coursewareUrl = result["coursewareUrl"]
if len(beginTs) > 10:
timesArray = beginTs.split('-')
time = timesArray[0] + timesArray[1] + timesArray[2][0:2]
fileName = time + subject
if len(fileName) > 25:
fileName = fileName[0:25]
fileName = fileName + '(' + str(i) + ')'
try:
if len(videoUrl) > 1:
if os.path.isfile('download/' + fileName + '.mp4') == False:
print fileName
print(videoUrl)
urllib.urlretrieve(videoUrl,"%s.mp4" %("download/" + fileName))
print (fileName + '---video---done')
if len(coursewareUrl) > 1:
urllib.urlretrieve(coursewareUrl,"%s.pdf" %("download/" + fileName))
print (fileName + '---pdf---done')
except:
print (fileName + '---error')
getVideo()
然后免费的视频都下载下来了(看代码也看到服务器是验证X-session的,就是一个固定的sessionToken)