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

相关推荐
临床数据科学和人工智能兴趣组2 小时前
在R语言中, 使用 as.factor() 函数转换数值型变量
开发语言·r语言
杨杨杨大侠5 小时前
Jev、Kev、Laya:决策模型怎么选,什么时候需要微调?
人工智能·python·agent
andyweike5 小时前
php笔记
开发语言·笔记·php
LOVE️YOU6 小时前
Python 在定义函数时,究竟定义的是什么?
python
段一凡-华北理工大学6 小时前
大模型应用开发 100 天:Python + LLM 从入门到精通 day26~Prompt 调试与优化——A/B 测试与效果评估
windows·python·大模型·prompt·智能体·提示词工程·高炉智能化
Minecraft红客6 小时前
以撒的结合
python·游戏·电脑·娱乐
Circ.6 小时前
Python 调试 Litellm 本地大模型接口:模型列表与对话接口实操踩坑记录
开发语言·python
风早爽太7 小时前
用 ‌Render‌ 快速部署网站和常见问题解决
python·fastapi
现任明教教主~8 小时前
Thinkphp站群蜘蛛池SaaS系统YanyvSEO含多用户/积分/六大引擎计费/易支付对接
java·开发语言·spring
李航19838 小时前
给自己的图形引擎,配上了AI渲染,做设计真是太方便了
人工智能·python·计算机视觉·ai·ai编程