你可以使用pandas库来读取excel文件,使用requests库来下载pdf文件,然后使用csv库来输出csv文件。下面是一个示例代码:

import pandas as pd
import requests
import csv

# 读取excel文件
df = pd.read_excel("data.xlsx")

# 创建csv文件并写入表头
with open("output.csv", "w", newline="") as f:
    writer = csv.writer(f)
    writer.writerow(["URL", "Relative Path"])

# 遍历excel中的pdfurl
for url in df["pdfurl"]:
    # 下载pdf文件
    response = requests.get(url)
    # 获取pdf文件的相对路径地址
    relative_path = url.split("/")[-1]

    # 写入csv文件
    with open("output.csv", "a", newline="") as f:
        writer = csv.writer(f)
        writer.writerow([url, relative_path])

    # 保存pdf文件
    with open(relative_path, "wb") as f:
        f.write(response.content)
``
撰写python代码读取excel中的pdfurl下载pdf文件并输出csv文件输出网址和对应的相对路径地址

原文地址: https://www.cveoy.top/t/topic/iClF 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录