本帖最后由 hc1jy 于 2023-3-23 09:32 编辑
起因 突然想学学逆向,然后看到在七周年的帖子有个逆向教程,于是在爱盘下载资料时发现只能一个一个下载文件不能一起下载
既然不能一次性点完,我也不想守在那里点,那就只能写个自动下载的脚本了
脚本是基本做好了,但是还有一些小问题,在正则的获取地址的时候,会拿到导航栏里面的工具地址,这并不是我们想要的,有没有正则大佬来帮我优化下
[Python] 纯文本查看 复制代码 import requests as r
import re
from urllib import parse
from tqdm import tqdm
url="https://down.52pojie.cn/%E5%90%BE%E7%88%B1%E7%A0%B4%E8%A7%A3%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B/%E5%90%BE%E7%88%B1%E7%A0%B4%E8%A7%A3%E8%AE%BA%E5%9D%9B%E5%AE%98%E6%96%B9%E5%85%A5%E9%97%A8%E6%95%99%E5%AD%A6%E5%9F%B9%E8%AE%AD%E7%AC%AC%E4%B8%80%E6%9C%9F/%E3%80%8A%E5%90%BE%E7%88%B1%E7%A0%B4%E8%A7%A3%E5%9F%B9%E8%AE%AD%E7%AC%AC%E4%B8%80%E8%AF%BE%EF%BC%9A%E7%A0%B4%E8%A7%A3%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E4%B9%8B%E4%BB%8B%E7%BB%8D%E5%B8%B8%E8%A7%81%E5%B7%A5%E5%85%B7%E5%92%8C%E5%A3%B3%E7%9A%84%E7%89%B9%E5%BE%81%E3%80%8B%E8%AE%B2%E5%B8%88%EF%BC%9AHmily/"
d_html=r.get(url)
pattern = re.compile('[a-zA-Z0-9%]+\.7z|[a-zA-Z0-9%]+\.zip|[a-zA-Z0-9%]+\.rar') #用来提取下载地址,正则学的不太好,有办法可以优化的大佬欢迎指出
d_url=pattern.findall(d_html.text)
print(d_url)
# a='%E5%90%BE%E7%88%B1%E7%A0%B4%E8%A7%A3%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B'
# name=parse.unquote(a)
# print(name)
def download(url: str, fname: str):
# 用流stream的方式获取url的数据
resp = r.get(url, stream=True)
# 拿到文件的长度,并把total初始化为0
total = int(resp.headers.get('content-length', 0))
# 打开当前目录的fname文件(名字你来传入)
# 初始化tqdm,传入总数,文件名等数据,接着就是写入,更新等操作了
with open(fname, 'wb') as file, tqdm(
desc=fname,
total=total,
unit='iB',
unit_scale=True,
unit_divisor=1024,
) as bar:
for data in resp.iter_content(chunk_size=1024):
size = file.write(data)
bar.update(size)
# 以上download方法来自:https://blog.csdn.net/chenchen5152/article/details/122469705
# url="https://down.52pojie.cn/%E5%90%BE%E7%88%B1%E7%A0%B4%E8%A7%A3%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B/%E5%90%BE%E7%88%B1%E7%A0%B4%E8%A7%A3%E8%AE%BA%E5%9D%9B%E5%AE%98%E6%96%B9%E5%85%A5%E9%97%A8%E6%95%99%E5%AD%A6%E5%9F%B9%E8%AE%AD%E7%AC%AC%E4%B8%80%E6%9C%9F/%E3%80%8A%E5%90%BE%E7%88%B1%E7%A0%B4%E8%A7%A3%E5%9F%B9%E8%AE%AD%E7%AC%AC%E4%B8%80%E8%AF%BE%EF%BC%9A%E7%A0%B4%E8%A7%A3%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E4%B9%8B%E4%BB%8B%E7%BB%8D%E5%B8%B8%E8%A7%81%E5%B7%A5%E5%85%B7%E5%92%8C%E5%A3%B3%E7%9A%84%E7%89%B9%E5%BE%81%E3%80%8B%E8%AE%B2%E5%B8%88%EF%BC%9AHmily/%E5%90%BE%E7%88%B1%E7%A0%B4%E8%A7%A3%E5%9F%B9%E8%AE%AD%E7%AC%AC%E4%B8%80%E8%AF%BE%E4%BD%9C%E4%B8%9A.7z"
# download(url,'asd.7z')
# url="https://down.52pojie.cn/%E5%90%BE%E7%88%B1%E7%A0%B4%E8%A7%A3%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B/%E5%90%BE%E7%88%B1%E7%A0%B4%E8%A7%A3%E8%AE%BA%E5%9D%9B%E5%AE%98%E6%96%B9%E5%85%A5%E9%97%A8%E6%95%99%E5%AD%A6%E5%9F%B9%E8%AE%AD%E7%AC%AC%E4%B8%80%E6%9C%9F/%E3%80%8A%E5%90%BE%E7%88%B1%E7%A0%B4%E8%A7%A3%E5%9F%B9%E8%AE%AD%E7%AC%AC%E4%B8%80%E8%AF%BE%EF%BC%9A%E7%A0%B4%E8%A7%A3%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E4%B9%8B%E4%BB%8B%E7%BB%8D%E5%B8%B8%E8%A7%81%E5%B7%A5%E5%85%B7%E5%92%8C%E5%A3%B3%E7%9A%84%E7%89%B9%E5%BE%81%E3%80%8B%E8%AE%B2%E5%B8%88%EF%BC%9AHmily/%E5%90%BE%E7%88%B1%E7%A0%B4%E8%A7%A3%E5%9F%B9%E8%AE%AD%E7%AC%AC%E4%B8%80%E8%AF%BE%E4%BD%9C%E4%B8%9A.7z"
# download(url,'996.7z')
#
for i in d_url:
new_url=url+i
name=parse.unquote(i)
download(new_url,name)
|