蓝奏云直链解析API网址:
https://api.xinac.net/lanzous?url=https://www.lanzoui.com/i3xcmaf
本教程基于Python开发
一、解析下载页面
参数url
为下载页面网址,如:https://www.lanzoui.com/i3xcmaf
def parse_1(url):
print('---> 原始网址:', url)
header = headers.get_header(referer=url)
req = request.Request(url=url, headers=header, method='GET')
response = request.urlopen(req, timeout=30)
resp = response.read().decode('utf-8', 'ignore')
bs = bs4.BeautifulSoup(resp, features='lxml')
if bs:
bs2 = bs.find_all("iframe")
if bs2:
print(src)
return bs2[0].get('src')
return None
参数:https://www.lanzoui.com/i3xcmaf
返回:/fn?UDYBa1o_aAmUFYQNnUzNVYVA_aVXYAKwM8UmRbaABlW24CNFE1AW0EZFU3Cmk_c
二、解析iframe链接页面
参数为https://www.lanzoui.com
加parse_1
的返回值
def parse_2(url):
header = headers.get_header(referer=url)
req = request.Request(url=url, headers=header, method='GET')
response = request.urlopen(req, timeout=30)
resp = response.read().decode('utf-8', 'ignore')
ajax_sign = re.findall(r'var ajaxdata = \'([\w]+?)\';', resp)
data = dict()
data['action'] = 'downprocess'
data['sign'] = ajax_sign[0]
data['ves'] = 1
print(data)
return data
参数:https://www.lanzoui.com/fn?UDYBa1o_aAmUFYQNnUzNVYVA_aVXYAKwM8UmRbaABlW24CNFE1AW0EZFU3Cmk_c
返回:{'action': 'downprocess', 'sign': 'B2EHOV5vATAIAVZpBjYCPgFjDjhRPAc3ATJWZVY_aBiFTJwBqDWFSMwdoUTMKaAAyAGpXa1U6ADU_c', 'ves': 1}
三、获取文件下载链接
此处有3个参数:
- url:
https://www.lanzoui.com/ajaxm.php
- referer:
parse_2
的参数url
- data:
parse_2
的返回值
得到的网址非最终链接。
def parse_3(url, referer, data):
print(url)
header = headers.get_header(referer=referer)
resp = requests.post(url, headers=header, data=data)
text = json.loads(resp.content)
if text and text['zt'] == 1:
href = text['dom'] + '/file/' + text['url']
print(href)
return href
return None
参数:
1. https://www.lanzoui.com/ajaxm.php
2. https://www.lanzoui.com/fn?UDYBa1o_aAmUFYQNnUzNVYVA_aVXYAKwM8UmRbaABlW24CNFE1AW0EZFU3Cmk_c
3. {'action': 'downprocess', 'sign': 'B2EHOV5vATAIAVZpBjYCPgFjDjhRPAc3ATJWZVY_aBiFTJwBqDWFSMwdoUTMKaAAyAGpXa1U6ADU_c', 'ves': 1}
返回:https://vip.d0.baidupan.com/file/?AGYCPFloAjNUXQM7BTACblBvUmoFs1bNUt0H6FaRBK8F4ADQXZ1SJglyAnQLuFftVrMH6lGHBrYCK1U+XXFQYgAmAjNZbQI6VGcDCgU4AmdQN1JvBWlWZlJnBzVWPwQwBSMAMV1zUjsJbgJkC2dXb1Y5BzpROwYyAiNVI11xUGwAMgJlWTUCb1QtA2UFZQIsUDhSYAV1VjZSYQdkVj8EMQU0AGFdN1IwCW4CZAtuVzdWPwc3UWoGMAI9VWddY1BkADcCZVlhAjVUMQM3BWkCZ1A5UmMFblZ6UjgHcVY5BCMFcAAkXWVSdAk2AjALYlduVjsHNlE9BjICM1V1XXVQOABtAjBZYgJrVDMDYAVoAjdQPFJkBWtWbFJhBzZWJAQrBSMAMV1sUnEJYgJlC2pXb1Y4BzRRPAY9AjdVY10xUHcAdQIlWXMCa1QzA2AFZAI1UDhSbgVvVm1SbQc5ViwEcAVsACddPVI1CWYCegtuV2NWOQcsUTwGNQIwVX1dOFBl
四、获取最终链接
参数url
为parse_3
的返回值
def parse_4(url):
print(url)
header = headers.get_header(lang='zh-CN,zh;q=0.9,en;q=0.8')
resp = requests.head(url, headers=header)
head = resp.headers
if resp.status_code == 301 or resp.status_code == 302:
print(head['Location'])
return head['Location']
else:
print('---> error: ', resp.status_code)
return None
返回:https://developer56.baidupan.com/071317bb/2019/04/27/b4e541676101a35d484b570ec3b8d344.mp3?st=0T1UeKCZgcchvgRVjfbRbA&e=1594632848&b=CbIAmVDYWbVQnlerBrMFhgLKCXUEKFB2U_bcIvlzkUrgF3gy_bV3kFbVRxUTQ_c&fi=8322455&pid=43-224-47-206&up=
五、注意事项
- 第3步获取的链接,经浏览器打开后可自动
跳转
并下载文件 - 第4步获取的链接,为文件的最终
下载链接
,不需要浏览器跳转 - 第3步和第4步获取的链接,有
时间戳
等参数,有效期3分钟
- 有效期过后,下载链接
失效
本文作者为新逸网络,转载请注明。