跳转链接批量解析工具 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

相关推荐
wuyk5558 分钟前
107.FreeRTOS 链表深度解析:从原理到面试满分答案
c语言·开发语言·数据结构·stm32·单片机·链表·面试
geovindu8 分钟前
CSharp: Wordcloud
开发语言·后端·c#·.net·.netcore·词云
智购科技自动售卖机厂家17 分钟前
2026自动售货机库存热力图分析:从设备分布到补货优先级的数据可视化实践~YH
大数据·python·信息可视化
Java小白笔记24 分钟前
Java 实现 ZIP 压缩包生成方案
java·开发语言·网络·7-zip
Persistent的粽子!25 分钟前
C++:类与对象(一)
开发语言·c++·经验分享·笔记
鹿鹿学长43 分钟前
微软把语音转写打到 0.1 美元/小时:5 个月降价 72%,AI 音频进入地板价时代
python·自动化
weixin_4407305044 分钟前
使用pytest中方法控制执行步骤(test_begin.py、test_end.py,@pytest.mark.run(order=1))
开发语言·python·pytest
小柯南敲键盘1 小时前
跨境电商批量图片翻译与视频字幕翻译,就用跨马AI工具
大数据·人工智能·python·音视频
geovindu1 小时前
CSharp: Command Pattern
开发语言·后端·c#·.net·.netcore·命令模式·行为模式
心易行者1 小时前
Python自动化测试7步落地法:用python在线运行省掉90%环境配置时间
java·开发语言·人工智能·python·log4j·ai编程