【问题标题】:How to parse a list of files from Sharepoint如何从 Sharepoint 解析文件列表
【发布时间】:2020-10-31 06:00:55
【问题描述】:

我是第一次使用 sharepy。这是我的代码:

import sharepy
import json

# (1) Authenticate
s = sharepy.connect("https://my_company.sharepoint.com",\
username="my_name@my_company.co.uk", password="my_password")

# (2) Get file information
r = s.get("https://my_company.sharepoint.com/Projects")
print(r)

它给出了输出:

<Response [200]>

所以请求已经成功。但是我不确定如何处理这个请求并从这个请求中获取文件列表。有什么想法吗?

【问题讨论】:

标签: python json api rest


【解决方案1】:

您的输出状态表明它是成功响应。因此,您现在可以在 r 中使用 response 并将其解析为 json 并将 json 响应转储到另一个文件。

以下取自here 的代码准确说明了如何获取文件的详细信息。

获取文件信息

data = r.json()
file = open("sharepoint.json", "w")
file.write(json.dumps(data, indent=4))
print("json file has been generated")

下载文件

r = s.getfile("https:// example.sharepoint.com/GroupSites/HR/_api/web\
/GetFileByServerRelativeUrl('/GroupSites/HR/Shared Documents/Team.xlsx')/$value"\
, filename = 'team.xlsx')
print("File Downloaded")

【讨论】:

    猜你喜欢
    • 2011-12-02
    • 1970-01-01
    • 2019-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    相关资源
    最近更新 更多