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

相关推荐
Scott9999HH3 小时前
【IIoT流量实战】蒸汽管道阀门全关却仍有流量?用 Python 实现涡街信号 FFT 频谱分析与温压全补偿积算网关,深度拆解靠谱的涡街流量计厂家硬核技术标准
开发语言·python
码智社4 小时前
AES加密原理详解及Java实现加解密实战
java·开发语言
AI云海4 小时前
python 列表、元组、集合和字典
开发语言·python
二十雨辰5 小时前
[爬虫]-Urllib
爬虫·python
萧瑟余晖5 小时前
JDK 26 新特性详解
java·开发语言
马优晨6 小时前
Freemarker 完整讲解(后端 Java 模板引擎)
java·开发语言·freemarker·freemarker 完整讲解·freemarker模板引擎
玉鸯6 小时前
Agent Hook:在概率推理之上,为 Agent 叠加确定性控制
python·langchain·agent
weixin_446260857 小时前
HACO:面向动态部署环境的对冲式智能计算可靠多智能体调度框架
后端·python·flask
我的xiaodoujiao7 小时前
API 接口自动化测试详细图文教程学习系列32--Allure测试报告2
python·学习·测试工具·pytest