import os import re import urllib.parse import sys
# 下载后的歌手文件,批量重命名 #例如: #原名字:artistInfo%3fcategory%3d0%26prefix%3d%26pn%3d1%26rn%3d60%26httpsStatus%3d1%26reqId%3d3b128760-1ce3-11f1-b0ff-171b6be4e54a%26plat%3dweb_www%26from%3d #新名字:pn1.json def rename_files(directory='.'): for filename in os.listdir(directory): filepath = os.path.join(directory, filename) if not os.path.isfile(filepath): continue
# 先尝试直接匹配编码后的 pn%3d数字 match = re.search(r'pn%3d(\d+)', filename, re.IGNORECASE) if not match: # 如果匹配不到,尝试解码后匹配 pn=数字 decoded = urllib.parse.unquote(filename) match = re.search(r'pn=(\d+)', decoded, re.IGNORECASE)
if __name__ == '__main__': target_dir = sys.argv[1] if len(sys.argv) > 1 else './artist_11' rename_files(target_dir)
使用python,自动调用浏览器模拟自动点击页码,这里只点击到169页
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.action_chains import ActionChains import time import sys import json import re
from selenium.webdriver.common.keys import Keys
import undetected_chromedriver as uc from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains import pandas as pd
print(f"\n{xpath_text}\n") times = 1 while True: time.sleep(1) try: #driver.find_element(By.XPATH,'//span[contains(text(),"编辑")]') ele = driver.find_element(By.XPATH, xpath_text) times += 1 return ele; except Exception as e: print(f"等待标签出现{times}秒") times+=1; if times > 60 : print("60秒结束等待") return None