冰凌汇编

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 40|回复: 0
收起左侧

[Python] 原创源码Python获取某云网盘下载直链

[复制链接]
OscarViolet 发表于 2022-8-10 23:47:25
[Python] 纯文本查看 复制代码
# -*- coding: utf-8 -*-
import time
 
import requests
requests.packages.urllib3.disable_warnings()
 
import re
import random
 
user_agents = [
    'Mozilla/5.0 (Linux; Android 8.0.0; SM-G955U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Mobile Safari/537.36',
    'Mozilla/5.0 (Linux; U; Android 9; zh-cn; Redmi Note 5 Build/PKQ1.180904.001) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.141 Mobile Safari/537.36 XiaoMi/MiuiBrowser/11.10.8',
    'Mozilla/5.0 (Linux; U; Android 8.1.0; zh-cn; BLA-AL00 Build/HUAWEIBLA-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/8.9 Mobile Safari/537.36',
    'Mozilla/5.0 (Linux; Android 8.1; PAR-AL00 Build/HUAWEIPAR-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044304 Mobile Safari/537.36 MicroMessenger/6.7.3.1360(0x26070333) NetType/WIFI Language/zh_CN Process/tools',
    'Mozilla/5.0 (Linux; Android 8.1.0; ALP-AL00 Build/HUAWEIALP-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/63.0.3239.83 Mobile Safari/537.36 T7/10.13 baiduboxapp/10.13.0.11 (Baidu; P1 8.1.0)',
    'Mozilla/5.0 (Linux; Android 6.0.1; OPPO A57 Build/MMB29M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/63.0.3239.83 Mobile Safari/537.36 T7/10.13 baiduboxapp/10.13.0.10 (Baidu; P1 6.0.1)',
    'Mozilla/5.0 (Linux; U; Android 8.0.0; zh-CN; MHA-AL00 Build/HUAWEIMHA-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/12.1.4.994 Mobile Safari/537.36',
    'Mozilla/5.0 (Linux; U; Android 8.1.0; zh-CN; EML-AL00 Build/HUAWEIEML-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/11.9.4.974 UWS/2.13.1.48 Mobile Safari/537.36 AliApp(DingTalk/4.5.11) com.alibaba.android.rimet/10487439 Channel/227200 language/zh-CN',
    'Mozilla/5.0 (Linux; Android 5.1.1; vivo X6S A Build/LMY47V; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044207 Mobile Safari/537.36 MicroMessenger/6.7.3.1340(0x26070332) NetType/4G Language/zh_CN Process/tools',
    'Mozilla/5.0 (Linux; U; Android 8.1.0; zh-CN; BLA-AL00 Build/HUAWEIBLA-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/11.9.4.974 UWS/2.13.1.48 Mobile Safari/537.36 AliApp(DingTalk/4.5.11) com.alibaba.android.rimet/10487439 Channel/227200 language/zh-CN',
    'Mozilla/5.0 (iPhone; U; CPU iPhone OS 8_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7',
]
 
# 下载域名
var_domian = 'pototo'
# 下载token
var_query = 'spototo'
 
default_domain = 'https://develope.lanzoug.com/file/'
 
# 请求超时
timeout = 50
 
# 蓝奏云Python真实地址解析
def get_lanzou_download_url(url, retryTimes=3):
    headers = {
        'origin': 'https://www.lanzous.com',
        'accept-language': 'zh-CN,zh;q=0.9',
        'X-Forwarded-For': '.'.join('%s' % random.randint(0, 255) for i in range(4)),
        'User-Agent': random.choice(user_agents)
    }
 
    # 加上tp, 手机端
    if url.rfind('/tp/') == -1:
        ridx = url.rindex('/')
        url = url[0:ridx] + '/tp' + url[ridx:]
        # print(url)
 
    # 请求下载页面
    resp = None
    try:
        # 忽略https检验,verify=False
        # requests.packages.urllib3.disable_warnings()
        resp = requests.get(url, headers=headers, timeout=timeout, verify=False)
        # print(resp.text)
    except Exception as err:
        print(err)
 
    if resp is None or not responseStatusOK(resp):
        retryTimes -= 1
        if retryTimes < 0:
            return None
        wait_some_time()
        return get_lanzou_download_url(url, retryTimes)
 
    # resp.encoding = "utf-8"
    page_content = resp.text
    if not page_content:
        print('Status: %u, Url: %s, content is empty' % (resp.status_code, resp.url))
        retryTimes -= 1
        if retryTimes < 0:
            return None
        wait_some_time()
        return get_lanzou_download_url(url, retryTimes)
 
    down_domain = default_domain
    # r: 不转义,原始字符串
    download_domian_match = re.search(r"var\s*" + var_domian + "\s*=\s*'(.+?)';", page_content)
    if download_domian_match:
        down_domain = download_domian_match.group(1)
 
    download_query = None
    download_query_match = re.search(r"var\s*" + var_query + "\s*=\s*'(.+?)';", page_content)
    if download_query_match:
        download_query = download_query_match.group(1)
 
    if down_domain and download_query:
        return down_domain + download_query
    else:
        print("Url: %s, down_domain:%s download_query: %s" %(resp.url, down_domain, download_query))
        return None
 
def responseStatusOK(resp):
    if resp is None:
        print('resp is None, Url: %s' % resp.url)
        return False
    if resp.status_code != requests.codes.OK:
        print('Status: %u, Url: %s' % (resp.status_code, resp.url))
        return False
    return True
 
def wait_some_time(minMls=1000, maxMls=5000):
    sleep_seconds = random.randint(minMls, maxMls) / 1000
    time.sleep(sleep_seconds)
    return sleep_seconds
 
if __name__ == '__main__':
    print(get_lanzou_download_url('https://wwd.lanzouw.com/i269V065bmza'))
冰凌汇编免责声明
以上内容均来自网友转发或原创,如存在侵权请发送到站方邮件9003554@qq.com处理。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|站点统计|Archiver|小黑屋|RSS|冰凌汇编 ( 滇ICP备2022002049号 滇公网安备 53032102000029号)|网站地图

GMT+8, 2022-9-25 07:49 , Processed in 0.121505 second(s), 8 queries , Redis On.

冰凌汇编 - 建立于2021年12月20日

Powered by Discuz! © 2001-2022 Comsenz Inc.

快速回复 返回顶部 返回列表