要获取 SharePoint 文件列表,您可以使用 'shareplum' 库来连接到 SharePoint,并使用 'get_folder' 方法来获取文件列表。

首先,您需要安装 'shareplum' 库。您可以使用以下命令安装它:

pip install shareplum

然后,您可以使用以下代码获取 SharePoint 文件列表:

from shareplum import Site
from shareplum import Office365

# SharePoint 网站的 URL 和凭据
sharepoint_url = 'https://your-sharepoint-site-url'
username = 'your-username'
password = 'your-password'

# 使用 Office365 身份验证连接到 SharePoint
authcookie = Office365(sharepoint_url, username=username, password=password).GetCookies()
site = Site(sharepoint_url, authcookie=authcookie)

# 获取文件列表
folder = site.Folder('Shared Documents')  # 替换为您的文件夹路径
files = folder.get_list_items()

# 打印文件列表
for file in files:
    print(file['FileLeafRef'])

请注意,您需要将上述代码中的 'your-sharepoint-site-url' 替换为您的 SharePoint 网站的 URL,并将 'your-username' 和 'your-password' 替换为您的凭据。

此外,您还需要将 'folder' 变量中的 'Shared Documents' 替换为您想要获取文件列表的文件夹路径。

Python 获取 SharePoint 文件列表 - 使用 shareplum 库

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

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