Check Google indexed page count for any domain using the "site:" search operator in Chrome Remote Debugging Protocol (CDP on localhost:9222). Use when the user wants to check how many pages Google has indexed for a website, compare indexing across multiple domains, or monitor SEO indexing status. Supports single or multiple domains with comparison table output.
通过Chrome远程调试协议(CDP)在localhost:9222上使用Google的site:搜索运算符,检查任意域名的已索引页面数量。
提取要检查的域名。支持:
对每个域名,在同一标签页中使用Page.navigate(不要创建新标签页):
{domain} 约有 {count} 个页面被Google索引。
| 域名 | 已索引页面数 | 备注 |
|---|---|---|
| example.com | 13,200 | — |
| example.org |
数据来源:Google site: 搜索运算符(近似值)
javascript
const WebSocket = require(/tmp/wsclient/node_modules/ws);
const http = require(http);
function cdpSend(ws, id, method, params) {
return new Promise(resolve => {
const handler = data => {
const msg = JSON.parse(data);
if (msg.id === id) resolve(msg);
};
ws.on(message, handler);
ws.send(JSON.stringify({id, method, params}));
});
}
function extractCount(text) {
if (!text) return NOT_FOUND;
const m = text.match(/找到约 ([\d,]+) 条结果/);
return m ? m[1].replace(/,/g, ) : PARSE_ERROR: + text;
}
async function main() {
// 1. 创建一个标签页
const target = await new Promise((resolve, reject) => {
const req = http.request({hostname: localhost, port: 9222, path: /json/new, method: PUT}, res => {
let d = ; res.on(data, c => d += c); res.on(end, () => resolve(JSON.parse(d)));
});
req.on(error, reject); req.end();
});
// 2. 连接WebSocket
const ws = new WebSocket(target.webSocketDebuggerUrl);
await new Promise(r => ws.on(open, r));
await cdpSend(ws, 1, Page.enable, {});
await cdpSend(ws, 2, Runtime.enable, {});
// 3. 循环处理域名
const domains = [[Name, example.com]]; // 替换为实际域名
for (const [name, domain] of domains) {
await cdpSend(ws, 10, Page.navigate, {url: https://www.google.com/search?q=site: + domain});
await new Promise(resolve => {
ws.on(message, data => {
const msg = JSON.parse(data);
if (msg.method === Page.loadEventFired) resolve();
});
});
await new Promise(r => setTimeout(r, 3000));
const r = await cdpSend(ws, 11, Runtime.evaluate, {expression: document.getElementById(result-stats)?.textContent || NOT_FOUND});
console.log(name + | + domain + | + extractCount(r.result.result.value));
}
// 4. 清理
ws.close();
http.request({hostname: localhost, port: 9222, path: /json/close/ + target.id, method: DELETE}, () => {}).end();
await new Promise(r => setTimeout(r, 1000));
// 5. 验证标签页已关闭
const remaining = await new Promise((resolve, reject) => {
const req = http.request({hostname: localhost, port: 9222, path: /json, method: GET}, res => {
let d = ; res.on(data, c => d += c); res.on(end, () => resolve(JSON.parse(d)));
});
req.on(error, reject); req.end();
});
console.log(剩余标签页数:, remaining.length);
process.exit(0);
}
main().catch(e => { console.error(e); process.exit(1); });
| 问题 | 解决方案 |
|---|---|
| 未找到#result-stats | 尝试div[id^=result]或document.body.innerText |
| Google验证码 |
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 google-index-checker-1775983081 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 google-index-checker-1775983081 技能
skillhub install google-index-checker-1775983081
文件大小: 3.18 KB | 发布时间: 2026-4-13 10:28