# -*- 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'))
某云直链获取 - 笔记记录
最新推荐文章于 2024-08-30 07:44:43 发布