UiPath Documentation
studio-web
latest
false
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。
UiPath logo, featuring letters U and I in white

Studio Web 用户指南

上次更新日期 2026年4月8日

通过 HTTP 调用进行分页

以下教程演示了如何使用“后条件循环”活动,通过重复进行 HTTP 调用,直到检索到所有数据为止,来处理 API 分页。

分页指示符(例如光标、页尾标志或限制)通常包含在响应标头、响应正文中,或作为查询参数包含。

此示例检索使用OpenBreweryDB API 的工厂列表。根据 OpenBreweryDB API 规范,分页使用基于偏移量(基于页面)的参数进行处理。要对数据集进行分页,请在 HTTP 请求中包含Per_page=X&page=Y作为查询参数。

  1. 添加HTTP活动并进行如下配置:

    • 方法— GET
    • 请求 URL
      https://api.openbrewerydb.org/v1/breweries?per_page=10&page=1
      https://api.openbrewerydb.org/v1/breweries?per_page=10&page=1
      
  2. 调试API 工作流以检索第一个工厂列表。

  3. 添加“脚本”活动并提供以下代码:

    const url = new URL($input.request.url);
    const currentPage = Number(url.searchParams.get("page"));
    
    return { nextPage: currentPage + 1, 
    content: $input.content}
    const url = new URL($input.request.url);
    const currentPage = Number(url.searchParams.get("page"));
    
    return { nextPage: currentPage + 1, 
    content: $input.content}
    

    使用$input而非$context可确保始终引用上一个执行的活动的输出,尤其是在循环块内。JavaScript 代码返回一个带有nextPagecontent属性的 JSON 对象。这些属性使您可以控制循环,例如: 当nextPage < 10内容不为 null时继续。

  4. 在现有HTTP活动之上添加“循环” >“Do While 循环”活动。

    1. “HTTP”活动和“脚本”活动移动到“后条件循环”活动主体中。
    2. “Do While循环”活动的“条件”设置为$input.nextPage < 5
    3. 对于HTTP活动,打开“请求 URL”属性的表达式编辑器,并将表达式更新为:
      "https://api.openbrewerydb.org/v1/breweries?per_page=10&page=" + ($input.nextPage == null ? 1 : $input.nextPage)
      "https://api.openbrewerydb.org/v1/breweries?per_page=10&page=" + ($input.nextPage == null ? 1 : $input.nextPage)
      
  5. 再次调试您的工作流,并注意“运行输出”面板的“输出”选项卡中的结果数组。

  6. “后条件循环”活动外部,添加“响应”活动并进行如下配置:

    • “类型” — 成功
    • 详细信息— 打开“表达式编辑器”,写入以下内容:
      $context.outputs.Do_While_1.results.flatMap(result => result.content.map(brewery => brewery.name))
      ```This summarizes the response at step 6 and lists only the names of the breweries.
      $context.outputs.Do_While_1.results.flatMap(result => result.content.map(brewery => brewery.name))
      ```This summarizes the response at step 6 and lists only the names of the breweries.
      
  7. “运行输出”面板的“输出”选项卡中复制结果,并将其配置为输出架构:

    1. 打开数据管理器面板。
    2. “输出”选项卡中,选择 “从有效负载生成” ,。
    3. “粘贴复制的结果”,然后选择“生成架构”

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新