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

Power Automate中如何从共享邮箱邮件提取指定URL并下载

解决Power Automate中提取指定文本后的URL问题

核心思路

基于Html to text的输出,通过字符串定位与截取函数,精准提取“Download Periodic Report”之后的目标URL。

具体表达式及解释

基础版(URL后接空格)

如果目标URL紧跟在“Download Periodic Report”之后,且以空格作为结束标识,使用以下表达式:

trim(
    slice(
        body('Html_to_text'),
        add(indexOf(body('Html_to_text'), 'Download Periodic Report'), length('Download Periodic Report')),
        indexOf(body('Html_to_text'), ' ', add(indexOf(body('Html_to_text'), 'Download Periodic Report'), length('Download Periodic Report')))
    )
)
  • indexOf(...):定位“Download Periodic Report”的起始位置
  • add(..., length(...)):计算目标文本结束后的位置(即URL的起始点)
  • indexOf(..., ' ', ...):从URL起始点开始,找到第一个空格的位置作为URL结束点
  • slice(...):截取起始点到结束点的内容
  • trim(...):去除URL前后的多余空格或制表符

适配换行结束的场景

如果URL后接换行符而非空格,将表达式中的空格替换为换行符:

trim(
    slice(
        body('Html_to_text'),
        add(indexOf(body('Html_to_text'), 'Download Periodic Report'), length('Download Periodic Report')),
        indexOf(body('Html_to_text'), newline(), add(indexOf(body('Html_to_text'), 'Download Periodic Report'), length('Download Periodic Report')))
    )
)

兼容URL为末尾内容的场景

如果URL是邮件文本的最后一段(无后续空格/换行),用length(body('Html_to_text'))作为结束点:

trim(
    slice(
        body('Html_to_text'),
        add(indexOf(body('Html_to_text'), 'Download Periodic Report'), length('Download Periodic Report')),
        if(
            greater(indexOf(body('Html_to_text'), ' ', add(indexOf(body('Html_to_text'), 'Download Periodic Report'), length('Download Periodic Report'))), 0),
            indexOf(body('Html_to_text'), ' ', add(indexOf(body('Html_to_text'), 'Download Periodic Report'), length('Download Periodic Report'))),
            length(body('Html_to_text'))
        )
    )
)

调试与注意事项

  1. 确认Html to text的输出中,“Download Periodic Report”文本完全匹配,无多余换行或空格
  2. 替换表达式中的body('Html_to_text')为实际步骤的输出引用(若步骤重命名,需同步修改)
  3. 可先将Html to text的输出放入单独的Compose步骤,便于调试表达式逻辑

内容的提问来源于stack exchange,提问作者Carly Carlyle Adams Cnf

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 07:42:37