跳转链接批量解析工具 python

写好了脚本,复制下面的内容,保存为 E:\test\resolve_links.py,然后运行:

python 复制代码
"""
跳转链接批量解析工具
"""

import os
os.environ['TEMP'] = 'C:\\temp'
os.environ['TMP'] = 'C:\\temp'

import pandas as pd
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import time

print("="*50)
print("跳转链接批量解析工具")
print("="*50)

input_file = r'E:\test\奥数.xlsx'
print(f"\n读取文件: {input_file}")

df = pd.read_excel(input_file)
b_col = df.iloc[:, 1].dropna().tolist()
print(f"共有 {len(b_col)} 个链接需要处理")

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')

print("\n正在启动浏览器...")

service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=chrome_options)
print("浏览器启动成功!\n")

results = []

for i, url in enumerate(b_col):
    try:
        driver.get(url)
        time.sleep(2)
        final_url = driver.current_url
        results.append(final_url)
        print(f"[{i+1:3d}/{len(b_col)}] {final_url}")
    except Exception as e:
        results.append(f"ERROR: {str(e)[:80]}")
        print(f"[{i+1:3d}/{len(b_col)}] 错误")

driver.quit()

output_df = pd.DataFrame({'原始链接': b_col, '最终地址': results})
output_df.to_excel(r'E:\test\out.xlsx', index=False)

print(f"\n完成!结果已保存到 E:\\test\\out.xlsx")

运行前需要:

安装 Python: https://www.python.org/downloads/

安装依赖:pip install pandas selenium webdriver-manager

确保有 Chrome 浏览器

然后运行:python E:\test\resolve_links.py

相关推荐
是小蟹呀^10 分钟前
【总结】LangChain中工具的使用
python·langchain·agent·tool
宝贝儿好19 分钟前
【LLM】第二章:文本表示:词袋模型、小案例:基于文本的推荐系统(酒店推荐)
人工智能·python·深度学习·神经网络·自然语言处理·机器人·语音识别
星晨雪海20 分钟前
基于 @Resource 的支付 Service 多实现类完整示例
java·开发语言
王夏奇36 分钟前
pythonUI界面弹窗设置的几种办法
python·ui
ACP广源盛1392462567343 分钟前
破局 Type‑C 切换器痛点@ACP#GSV6155+LH3828/GSV2221+LH3828 黄金方案
c语言·开发语言·网络·人工智能·嵌入式硬件·计算机外设·电脑
ZhengEnCi1 小时前
P2B-Python可迭代对象完全指南-从列表到生成器的Python编程利器
python
Ricky_Theseus1 小时前
C++右值引用
java·开发语言·c++
Rick19931 小时前
Java内存参数解析
java·开发语言·jvm
勿忘,瞬间1 小时前
多线程之进阶修炼
java·开发语言
萌萌站起1 小时前
Vscode 中 python模块的导入问题
ide·vscode·python