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

如何在BigQuery SQL中从URL提取utm_content参数

提取URL中utm_content参数的实用方法

下面是几种不同场景下提取URL里utm_content参数值的方法:

1. Python 实现(后端/数据处理场景)

用Python标准库的urllib.parse就能轻松搞定,不需要额外安装依赖:

from urllib.parse import urlparse, parse_qs

# 替换成你的目标URL
target_url = "https:/www.xxxxxx.com/br/pt/yyyyy/example?origin=ALL&destination=ALL&utm_source=salesforce&utm_medium=email&utm_campaign=just_an_example_ok&utm_content=I_would_like_just_this_part_of_the_string"

# 解析URL并提取查询参数
parsed = urlparse(target_url)
params = parse_qs(parsed.query)
# 获取utm_content的值,没有则返回空字符串
utm_content_value = params.get('utm_content', [''])[0]

print(utm_content_value)

2. 正则表达式(通用跨语言场景)

如果需要在多种语言或工具里复用,正则表达式是通用方案,匹配规则为 utm_content=([^&]+),意思是匹配utm_content=之后直到下一个&或URL结尾的所有内容。

Python 正则示例

import re

target_url = "https:/www.xxxxxx.com/br/pt/yyyyy/example?origin=ALL&destination=ALL&utm_source=salesforce&utm_medium=email&utm_campaign=just_an_example_ok&utm_content=I_would_like_just_this_part_of_the_string"

match_result = re.search(r'utm_content=([^&]+)', target_url)
if match_result:
    utm_content_value = match_result.group(1)
    print(utm_content_value)

Excel 公式实现(办公场景)

如果是在Excel里处理批量URL,可以直接用公式(假设URL在A1单元格):

=IFERROR(MID(A1,FIND("utm_content=",A1)+12,IFERROR(FIND("&",A1,FIND("utm_content=",A1)),LEN(A1))-FIND("utm_content=",A1)-12),"")

公式逻辑:先定位utm_content=的位置,再截取后面的内容,遇到&就停止,没有&就取到URL末尾,IFERROR用来处理URL里没有utm_content的情况,返回空值。

3. JavaScript 实现(前端/Node.js场景)

用浏览器或Node.js自带的URL对象,解析参数非常方便:

const targetUrl = "https:/www.xxxxxx.com/br/pt/yyyyy/example?origin=ALL&destination=ALL&utm_source=salesforce&utm_medium=email&utm_campaign=just_an_example_ok&utm_content=I_would_like_just_this_part_of_the_string";
const urlObj = new URL(targetUrl);
const utmContentValue = urlObj.searchParams.get('utm_content');

console.log(utmContentValue);

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 12:01:20