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

相关推荐
阿里嘎多学长5 小时前
2026-10-20 GitHub 热点项目精选
开发语言·程序员·github·代码托管
happylifetree5 小时前
Python67:核心语法-函数进阶-参数类型(函数作为参数)
python
布吉岛的石头5 小时前
Java 程序员第 50 阶段2:预训练的目标函数:自回归语言建模本质
java·开发语言·人工智能·深度学习·回归·transformer
小羊没烦恼!6 小时前
铁道部新客票系统设计(二)
开发语言·前端·数据库·python·oracle·c#·php
quantdash_cc6 小时前
从实时行情到价格观察表:用 Python 和 Pandas 构建策略输入数据
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
镜子AI6 小时前
镜子AI工程实践:用 Python 做 GEO 实体一致性审计,并自动生成 JSON-LD 结构化数据
人工智能·python·json
昂好的day7 小时前
VisionMaster 通信模块实战(上):Modbus、TCP 收发、协议组装解析
开发语言·网络·网络协议·tcp/ip·c#
努力实干8 小时前
面向对象设计原则——C++
开发语言·c++·数码相机
NetX行者10 小时前
四语言 Hello World 背后:编译模型与运行时对比
开发语言
Pin_Qing11 小时前
账单没超,请求先被拒了
大数据·开发语言·人工智能