蓝奏云直链解析开发流程

新逸Cary 132 0
广告

 

蓝奏云直链解析API网址:

https://api.xinac.net/lanzous?url=xxx

本教程基于Python开发

一、解析下载页面

参数url为下载页面网址,如:https://www.lanzous.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.lanzous.com/i3xcmaf    

返回:/fn?UDYBa1o_aAmUFYQNnUzNVYVA_aVXYAKwM8UmRbaABlW24CNFE1AW0EZFU3Cmk_c

二、解析iframe链接页面

参数为https://www.lanzous.comparse_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 ajaxup = \'([\w]+?)\';', resp)
    data = dict()
    data['action'] = 'downprocess'
    data['sign'] = ajax_sign[0]
    data['ves'] = 1
    print(data)
    return data
参数:https://www.lanzous.com/fn?UDYBa1o_aAmUFYQNnUzNVYVA_aVXYAKwM8UmRbaABlW24CNFE1AW0EZFU3Cmk_c

返回:{'action': 'downprocess', 'sign': 'B2EHOV5vATAIAVZpBjYCPgFjDjhRPAc3ATJWZVY_aBiFTJwBqDWFSMwdoUTMKaAAyAGpXa1U6ADU_c', 'ves': 1}

三、获取文件下载链接

此处有3个参数:

  • url:https://www.lanzous.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.lanzous.com/ajaxm.php
2. https://www.lanzous.com/fn?UDYBa1o_aAmUFYQNnUzNVYVA_aVXYAKwM8UmRbaABlW24CNFE1AW0EZFU3Cmk_c
3. {'action': 'downprocess', 'sign': 'B2EHOV5vATAIAVZpBjYCPgFjDjhRPAc3ATJWZVY_aBiFTJwBqDWFSMwdoUTMKaAAyAGpXa1U6ADU_c', 'ves': 1}

返回:https://vip.d0.baidupan.com/file/?AGYCPFloAjNUXQM7BTACblBvUmoFs1bNUt0H6FaRBK8F4ADQXZ1SJglyAnQLuFftVrMH6lGHBrYCK1U+XXFQYgAmAjNZbQI6VGcDCgU4AmdQN1JvBWlWZlJnBzVWPwQwBSMAMV1zUjsJbgJkC2dXb1Y5BzpROwYyAiNVI11xUGwAMgJlWTUCb1QtA2UFZQIsUDhSYAV1VjZSYQdkVj8EMQU0AGFdN1IwCW4CZAtuVzdWPwc3UWoGMAI9VWddY1BkADcCZVlhAjVUMQM3BWkCZ1A5UmMFblZ6UjgHcVY5BCMFcAAkXWVSdAk2AjALYlduVjsHNlE9BjICM1V1XXVQOABtAjBZYgJrVDMDYAVoAjdQPFJkBWtWbFJhBzZWJAQrBSMAMV1sUnEJYgJlC2pXb1Y4BzRRPAY9AjdVY10xUHcAdQIlWXMCa1QzA2AFZAI1UDhSbgVvVm1SbQc5ViwEcAVsACddPVI1CWYCegtuV2NWOQcsUTwGNQIwVX1dOFBl

四、获取最终链接

参数urlparse_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=

五、注意事项

  1. 第3步获取的链接,经浏览器打开后可自动跳转并下载文件
  2. 第4步获取的链接,为文件的最终下载链接,不需要浏览器跳转
  3. 第3步和第4步获取的链接,有时间戳等参数,有效期3分钟
  4. 有效期过后,下载链接失效

本文链接:https://www.cary.tech/article/546.html

原文链接:https://blog.xinac.cn/archives/api-lanzous.html


 

发表评论 取消回复
表情 图片 链接 代码

分享