python下载电影_使用python下载VIP电影

#coding=utf-8

import urllib

import urllib2

import re

#url='https://www.mgtv.com/b/316354/4256331.html'#下载的电影视频

#http://4.wjsou.com/#API接口

url=raw_input(unicode("请输入电影地址:","utf-8").encode("gbk"))

def down_movie(url):

api = "https://000o.cc/2018/api.php"

headers = {"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}

post={

"referer":"http://000o.cc/jx/ty.php?url="+url,

"time":"1528635404",

"key":"8553f0e81b786829b6869b82fcf27bd4",

"url":url

}

data = urllib.urlencode(post)

request = urllib2.Request(api, data=data, headers = headers)

response = urllib2.urlopen(request)

html=response.read()

#print(html)

pattern = re.compile(r'(http.*?)"')

movie=pattern.findall(html)

movieurl=movie[0].replace("\\","")

#movieurl=urllib.unquote(movieurl)

print(u"下载电影地址为:%s" % movieurl)

response=urllib2.urlopen(movieurl)

moviehtml=response.read()

file = open('movies.mp4','wb')

#创建该文件

file.write(moviehtml)

file.close()

print(u'电影下载完成')

down_movie(url)

你可能感兴趣的:(python下载电影)