好友
阅读权限10
听众
最后登录1970-1-1
|
本帖最后由 dengdengda 于 2021-7-30 09:26 编辑
最近想做个下载的中转站,但是遇见了个奇怪的问题:
通过某网站得到的高速下载链接,包括普通下载和迅雷下载。
样子是这样的:
迅雷按键的源代码:
<a href="javascript: ;" class="btn btn-info btn-sm" thunder-link="https://s16.rosefile.net/d/MDAwMDAwMDAwMJOAeZ2w0KXfgLRqq7KqcKmyhXFrgYiChpOJepGH1KLQkaSgrLyWquB_z6Kkx3SSnMp6e6eWoIqYnXugrIy6Ztl-ooGWsrqtmYHLg6w/A4454.zip">迅雷下载1</a>
普通高速下载的源代码:
<a target="_blank" class="btn btn-info btn-sm">高速下载2</a>
这种的链接,如果我直接点击就会弹出迅雷或者IDM,可以下载
但是如果我复制内容里面的链接发给朋友,就不能下,样子是这样的:(还不会上传附件,用语言描述一下吧)
普通下载:
IDM提示
IDM读不出来文件大小、类型等这些信息,点击下载会提示无法下载此文件,备注HTTP/1.1 500
迅雷下载:
迅雷行为
会下下来一个只有几k的文件,并且无法打开,提示错误
希望高手能够解答疑惑,给个解决方案,感激不尽
PS:最新进展
如果我用浏览器完成第一步的操作,然后复制下载地址到python里面,读取文件头后用IDM可以下载
但如果我第一次POST,第二次GET全部在python里面用request完成,最终地址复制到IDM就不可以
求大神指点迷津
第一个是全部用request提交的代码,第二个是第一次在浏览器手动打开复制相关信息后仅仅第二次用request提交的代码,
[Python] 纯文本查看 复制代码 # -*- coding: utf-8 -*-
"""
Created on Wed Jul 28 17:51:00 2021
@author: Administrator
"""
import requests
from bs4 import BeautifulSoup
import re
from faker import Faker
import os
import time
ua = Faker()
#UB = ua.user_agent()
UB = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36'
#key = input('请定义key:') #读取key
dizhi = input('请输入:') #获取原始链接
key = '0F0BD868D9E365112CA5E6D3530FE861'
def first_tj(): #提交获取响应
cookies = {
'card': key,
}
headers = {
'Origin': 'http://pan.codest.me',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.8',
'Upgrade-Insecure-Requests': '1',
'User-Agent': UB,
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Cache-Control': 'max-age=1',
'Referer': 'http://pan.codest.me/',
'Connection': 'keep-alive',
}
data = {
'browser': '',
'url': dizhi,
'card': key
}
url = 'http://pan.codest.me/doOrder4Card'
response = requests.post(url, headers=headers, cookies=cookies, data=data)
if response.status_code == 200:
global html
global html1
global url_sec
html = BeautifulSoup(response.text,features='lxml') #获取页面源码
html1 = response.text
url_sec = response.url #获取二次提交需要的url数据
panduan()
else:
print('网络错误,请重试')
def panduan():
a = re.findall('<p class="text-muted">同时可以下载一个文件,支持浏览器下载或者右键迅雷下载</p>', html1)
if len(a) == 0:
yichang()
else:
tiqu_rose()
def yichang():
cuowu = html.select('body > div > div > div > p:nth-child(3)')
print(cuowu)
def tiqu_rose(): #rose提取链接
link_a = html.select('#form_panel > div:nth-child(8) > div > a:nth-child(1)')
link_b = str(link_a)
#print(link_b)
link_1 = link_b.split('"')
print(link_1[3])
time.sleep(5)
#print(link_1)
global link_sec
link_sec = link_1[3] #获取二次提交需要的地址
sec_tijiao_rose()
def sec_tijiao_rose(): #二次提交
address = link_sec.split('=')
link = address[1]
disk = address[3]
address_2 = link_sec.split('link=')
url_sec = address_2[0]
headers = {
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Upgrade-Insecure-Requests': '1',
'User-Agent': UB,
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Referer': url_sec,
'Accept-Language': 'zh-CN,zh;q=0.9',
}
params = (
('link', link),
('disk', disk),
)
url = 'xin220.7z'
def download_file(url, save_path=""):
if save_path == "":
save_path = url.split(os.path.sep)[-1]
with requests.get(url_sec,params=params,headers=headers,stream=True) as fget:
# 此时只有响应头被下载
file_size = int(fget.headers["Content-Length"])
print('-' * 32)
print(f"Name: {save_path}")
print(f"Size: {file_size/(1000**2)}Mb")
print(f"Link: {url}")
print('-' * 32)
if __name__ == "__main__":
download_file(url)
first_tj()
[Python] 纯文本查看 复制代码 import os
import requests
import sys
address = input('请输入下载链接:')
address1 = address.split('=')
link = address1[1]
disk = address1[3]
headers = {
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Referer': 'http://pan.codest.me/pay/confirm/1/870586864896053248',
'Accept-Language': 'zh-CN,zh;q=0.9',
}
params = (
('link', link),
('disk', disk),
)
url = 'xin220.7z'
def download_file(url, save_path=""):
if save_path == "":
save_path = url.split(os.path.sep)[-1]
with requests.head('http://d6.fvprxbf.cn/toDownload?',params=params,headers=headers,stream=True) as fget:
# 此时只有响应头被下载
file_size = int(fget.headers["Content-Length"])
print('-' * 32)
print(f"Name: {save_path}")
print(f"Size: {file_size/(1000**2)}Mb")
print(f"Link: {url}")
print('-' * 32)
if __name__ == "__main__":
download_file(url)
|
|