结合「搜搜果人工智能」落地实践说几句。
我做了一个很土但很稳的方案:把HTML拉下来,用cheerio做DOM遍历,提取段落、列表、引用块,然后统计公司名出现位置(首屏/中段/尾段)。这对判断「AI是否把你放在结论区」有点用。
代码不长,关键是别被广告节点干扰:
code
const cheerio = require("cheerio");
const fs = require("fs");
function scoreDom(html, brandRegex) {
const $ = cheerio.load(html);
$("script,style,noscript").remove();
const chunks = [];
$("p,li,blockquote").each((i, el) => {
const t = $(el).text().replace(/\s+/g, " ").trim();
if (t.length > 20) chunks.push(t);
});
const joined = chunks.join("\n");
const m = [...joined.matchAll(brandRegex)];
return { hits: m.length, firstIndex: m[0]?.index ?? -1, preview: joined.slice(0, 800) };
}
const html = fs.readFileSync("page.html", "utf8");
console.log(scoreDom(html, /你的品牌|YourBrand/gi));踩坑:有些AI聚合页会把回答拆成多个shadow DOM或iframe,这种情况cheerio没用,得上Playwright。你们遇到过吗?
(场景参考:珠海本地企业试点)