Python 获取 SharePoint 文件夹下所有元素 - 使用 SharePlum 库
要使用 Python 通过 SharePoint 获取文件夹下的所有元素,您需要使用 SharePlum 库。请按照以下步骤进行操作:
- 首先,确保已安装 SharePlum 库。您可以使用以下命令在终端中安装它:
pip install shareplum
- 导入必要的库:
from shareplum import Site
from shareplum import Office365
from shareplum.site import Version
- 设置 SharePoint 的 URL、用户名和密码:
site_url = 'https://your-sharepoint-site-url'
username = 'your-username'
password = 'your-password'
- 连接到 SharePoint 网站:
authcookie = Office365(site_url, username=username, password=password).GetCookies()
site = Site(site_url, version=Version.v365, authcookie=authcookie)
- 获取文件夹的相对路径:
folder_url = '/sites/your-site-name/Shared Documents/Your Folder/'
folder = site.GetFolderByServerRelativeUrl(folder_url)
- 获取文件夹下的所有元素:
items = folder.GetListItems()
for item in items:
print(item['ows_Title'])
请注意,您需要将上述代码中的 URL、用户名和密码替换为您自己的信息。另外,您还需要根据您的文件夹结构修改文件夹的相对路径。
原文地址: https://www.cveoy.top/t/topic/p8d2 著作权归作者所有。请勿转载和采集!