python根据正则表达式生成指定规律的网址
import os def file_name(file_dir): for root, dirs, files in os.walk(file_dir): print(root) #当前目录路径 print(dirs) #当前路径下所有子目录 print(files) #当前路径下所有非目录子文件 dir1="d:/tu1" dir1="https://cdn.deere.com:2020/57-tuimm/uploads/allimg/2002101/" #file_name(dir1) import exrex for i in range(5): aa=exrex.getone(r\'\d{1,4}\') print(dir1+aa+".jpg") i+=1
结果:
================== RESTART: D:/Python/Python37/lian0213a.py ==================
https://cdn.deere.com:2020/57-tuimm/uploads/allimg/2002101/7061.jpg
https://cdn.deere.com:2020/57-tuimm/uploads/allimg/2002101/0.jpg
https://cdn.deere.com:2020/57-tuimm/uploads/allimg/2002101/20.jpg
https://cdn.deere.com:2020/57-tuimm/uploads/allimg/2002101/202.jpg
https://cdn.deere.com:2020/57-tuimm/uploads/allimg/2002101/0601.jpg
>>>