You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Office365-REST-Python-Client读取SharePoint(MS-List)超100行数据

解决SharePoint列表仅返回前100条记录的问题

SharePoint REST API默认采用分页机制,单次请求最多返回100条记录。要获取5000条上限内的所有列表项,可以通过以下两种方式实现:

方法1:使用库内置的批量获取方法

最新版的Office365-REST-Python-Client提供了get_all_items()方法,可自动处理分页,一次性获取所有符合条件的列表项(上限5000条):

sp_lists = ctx.web.lists
s_list = sp_lists.get_by_title(staff_list)
# 使用get_all_items()替代get_items()
l_items = s_list.get_all_items()
ctx.load(l_items)
ctx.execute_query()

# 遍历所有获取到的项
for item in l_items:
    print(item.properties)

方法2:手动处理分页(兼容旧版本库)

如果你的库版本不支持get_all_items(),可以手动识别分页标记,循环请求直到获取所有数据:

sp_lists = ctx.web.lists
s_list = sp_lists.get_by_title(staff_list)
all_items = []

# 初始请求获取第一页数据
current_page = s_list.get_items()
ctx.load(current_page)
ctx.execute_query()
all_items.extend(current_page)

# 检查是否存在下一页,循环获取剩余数据
while current_page.paged.__next__:
    current_page = s_list.get_items().skip(current_page.paged.__next__.skip).top(current_page.paged.__next__.top)
    ctx.load(current_page)
    ctx.execute_query()
    all_items.extend(current_page)

# all_items变量中已存储所有列表项
for item in all_items:
    print(item.properties)

注意:SharePoint列表视图的项目限制默认是5000条,若列表数据超过5000条,需要先调整列表的项目限制设置,或者通过CAML查询进行分段筛选获取。

内容的提问来源于stack exchange,提问作者Bob Fishcake

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 09:31:35