蓝奏云直链解析开发流程 lanzou

Admin 软件程序评论24,5512字数 2991
摘要

蓝奏云盘是网众公司为用户打造的网盘云存储,文件分发服务。本文介绍蓝奏云直链解析开发流程和直链API服务。

蓝奏云直链解析API网址:

https://api.xinac.net/lanzous?url=https://www.lanzoui.com/i3xcmaf文章源自新逸网络-https://www.xinac.net/8785.html

本教程基于Python开发文章源自新逸网络-https://www.xinac.net/8785.html

一、解析下载页面

参数url为下载页面网址,如:https://www.lanzoui.com/i3xcmaf文章源自新逸网络-https://www.xinac.net/8785.html

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.comparse_1的返回值文章源自新逸网络-https://www.xinac.net/8785.html

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个参数:文章源自新逸网络-https://www.xinac.net/8785.html

  • url:https://www.lanzoui.com/ajaxm.php
  • referer:parse_2的参数url
  • data:parse_2的返回值

得到的网址非最终链接。文章源自新逸网络-https://www.xinac.net/8785.html

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

四、获取最终链接

参数urlparse_3的返回值文章源自新逸网络-https://www.xinac.net/8785.html

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.xinac.net/8785.html文章源自新逸网络-https://www.xinac.net/8785.html
weinxin
新逸IT技术
扫一扫关注微信公众号
Admin
  • 本文由 发表于 2020-07-13
  • 转载请注明:https://www.xinac.net/8785.html
Favicon图标自动获取API 软件程序

Favicon图标自动获取API

  favicon.ico图标是网站的缩略标志,可以显示在浏览器标签、地址栏左边和收藏夹,是展示网站个性的缩略logo标志,也可以说是网站头像,如果要让网站看起来更专业、更美、更有个性,fa...
评论  0  访客  0
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定