|
发表于 2025-4-2 16:49:51
|
显示全部楼层
河南省郑州市
[color=rgba(0, 0, 0, 0.9)]1.实现了基本的解析流程,可以获取文件信息和下载链接import requests from urllib.parse import urlparse import re class LanzouAPI: def __init__(self): self.session = requests.Session() self.headers = { 'User-Agent': 'Mozilla/5.0...', 'Referer': 'https://www.lanzoui.com/' } def get_file_info(self, share_url): # 提取文件ID parsed = urlparse(share_url) file_id = parsed.path.split('/')[-1] # 获取初始页面提取关键参数 resp = self.session.get(share_url, headers=self.headers) html = resp.text sign = re.search(r"sign\s*:\s*'(.+?)'", html).group(1) action = re.search(r"action\s*:\s*'(.+?)'", html).group(1) # 构造API请求 api_url = 'https://www.lanzoui.com/ajaxm.php' data = {'action': action, 'sign': sign} api_resp = self.session.post(api_url, data=data, headers=self.headers) return api_resp.json()
2.[color=rgba(0, 0, 0, 0.9)]对于带密码的分享链接,需要额外处理密码验证步骤,[color=rgba(0, 0, 0, 0.9)]这个扩展功能可以处理需要密码的分享链接
def parse_with_pwd(self, share_url, pwd): # 获取验证参数 resp = self.session.get(share_url) html = resp.text data = { 'action': 'downprocess', 'sign': re.search(r"sign\s*:\s*'(.+?)'", html).group(1), 'p': pwd, 'ves': 1 } # 提交密码验证 verify_resp = self.session.post( 'https://www.lanzoui.com/ajaxm.php', data=data, headers=self.headers ) return verify_resp.json()
3.[color=rgba(0, 0, 0, 0.9)]针对蓝奏云的反爬措施,需要特别注意:1)请求频率控制;2)完整请求头模拟;3)cookie维持;4)动态参数处理。建议添加以下防御措施:
[color=rgba(0, 0, 0, 0.9)]
# 在__init__中添加 self.headers.update({ 'Accept': 'application/json, text/javascript, */*; q=0.01', 'X-Requested-With': 'XMLHttpRequest', 'Origin': 'https://www.lanzoui.com' }) # 请求间隔控制 import time time.sleep(random.uniform(1, 3))
全部PYTHON完成
|
|