简体   繁体   English

如何从 Sharepoint 解析文件列表

[英]How to parse a list of files from Sharepoint

I am using sharepy for the first time.我第一次使用sharepy。 Here is my code:这是我的代码:

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)

Which gives the output:这给出了 output:

<Response [200]>

So the request has been successful.所以请求成功了。 However I am unsure how to handle this request and get the list of files from this request.但是我不确定如何处理这个请求并从这个请求中获取文件列表。 Any ideas?有任何想法吗?

Your output status suggests that its a success response.您的 output 状态表明它是成功响应。 So you can now use that response in r and parse it to json and dump the json response to another file.因此,您现在可以在r中使用该response并将其解析为json并将json响应转储到另一个文件。

The code below taken from here illustrates exactly how you can get details on the files.下面从这里获取的代码准确地说明了如何获取文件的详细信息。

Get file information获取文件信息

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

Download file下载文件

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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM