工作流文件
n8n-网页列表抓成表格-国内版.json
{"name":"网页列表抓成表格(国内版)","nodes":[{"parameters":{"content":"## 网页列表抓成表格(国内版)\n派派编辑部改自 n8n 官方模板库 #2552。\n\n**第一次用:**\n1. 双击「模型」→ Credential to connect with → Create new credential,填 DeepSeek 的 API Key,Model 选 deepseek-flash\n2. 点右上角 Publish 发布\n3. 双击「填网址」,复制 Production URL,在登录了 n8n 的浏览器里打开;第一次会问能不能用你的 n8n 账号运行,点 Allow access\n\n**抓取规矩(工作流里已经做了的):**\n- 先读网站的 robots.txt,不让抓就停\n- 一次只抓你填的这一页;同一个网站 30 秒内只抓一次\n- 不带任何登录信息;遇到登录页、401 / 403 就停\n- 表格里的手机号、邮箱、微信号、身份证号会被程序去掉\n\n**你自己要守的:** 先看网站的用户协议,禁止抓取的不抓;不抓个人信息;不拿来批量搬运别人的内容。\n\n**Jina Reader:** 表单里选了它,你填的网址会发给 Jina(总部在德国、已被美国 Elastic 收购)去打开,默认用它的国内备用地址 r.jinaai.cn。","height":700,"width":560,"color":4},"id":"2e67d041-7a7c-5ab6-bf52-3459caa902cb","name":"说明","type":"n8n-nodes-base.stickyNote","typeVersion":1,"position":[-1000,-260]},{"parameters":{"formTitle":"网页列表抓成表格","formDescription":"填一个列表页的网址(招聘列表、商品列表、新闻公告列表……),AI 把页面上的每一条整理成表格的一行,看完可以下载成 Excel。一次只抓这一页,大约半分钟到一分钟。","formFields":{"values":[{"fieldLabel":"列表页网址","fieldName":"url","placeholder":"https://","requiredField":true},{"fieldLabel":"想要哪几列(选填,用顿号隔开)","fieldName":"columns","placeholder":"例如:职位、公司、薪资、城市、发布日期、链接"},{"fieldLabel":"抓取方式","fieldName":"mode","fieldType":"radio","requiredField":true,"defaultValue":"n8n 直接抓(网址不经过别人)","fieldOptions":{"values":[{"option":"n8n 直接抓(网址不经过别人)"},{"option":"Jina Reader 代抓(能抓 JavaScript 加载的页面,网址会发给 Jina)"}]}},{"fieldLabel":"抓之前确认一下","fieldName":"confirm","fieldType":"checkbox","requiredField":true,"fieldOptions":{"values":[{"option":"这一页不用登录就能看,网站的用户协议没有禁止抓取,我不抓个人信息"}]}}]},"authentication":"n8nUserAuth","responseMode":"lastNode","options":{"appendAttribution":false,"buttonLabel":"开始抓"}},"id":"2b67fed4-a710-5201-b3b7-3ce8d4da2a0f","name":"填网址","type":"n8n-nodes-base.formTrigger","typeVersion":2.6,"position":[-360,160]},{"parameters":{"mode":"runOnceForEachItem","jsCode":"// 整理网址;挡掉内网地址;同一个网站 30 秒内只抓一次\nconst ALLOW_PRIVATE = false;\nconst MIN_GAP_SECONDS = 30;\nlet url = String($json.url || '').trim();\nif (url && !/^https?:\\/\\//i.test(url)) url = 'https://' + url;\nlet problem = '', host = '', origin = '', path = '/';\n// Code 节点里没有 URL 对象,用正则拆网址\nconst m = url.match(/^(https?):\\/\\/(?:[^\\/?#@]*@)?(\\[[^\\]]+\\]|[^\\/?#:]+)(:\\d+)?([^#]*)/i);\nif (m && /[a-z0-9]/i.test(m[2])) {\n host = m[2].toLowerCase();\n origin = m[1].toLowerCase() + '://' + host + (m[3] || '');\n path = m[4] || '/';\n if (!path.startsWith('/')) path = '/' + path;\n} else problem = '网址格式不对,请复制浏览器地址栏里的完整网址,例如 https://www.example.com/list';\nif (!problem && !ALLOW_PRIVATE && (/^(localhost|0\\.0\\.0\\.0|\\[?::1\\]?)$/.test(host) || /^(127|10)\\./.test(host) || /^192\\.168\\./.test(host) || /^172\\.(1[6-9]|2\\d|3[01])\\./.test(host) || /^169\\.254\\./.test(host) || host.endsWith('.local') || host.endsWith('.internal'))) {\n problem = '为了安全,不抓内网地址(localhost、192.168.x.x 这类)。';\n}\nif (!problem) {\n const store = $getWorkflowStaticData('global');\n store.lastFetch = store.lastFetch || {};\n const now = Date.now();\n const last = store.lastFetch[host] || 0;\n if (now - last < MIN_GAP_SECONDS * 1000) {\n problem = `同一个网站 ${MIN_GAP_SECONDS} 秒内只抓一次,请过 ${Math.ceil((MIN_GAP_SECONDS * 1000 - (now - last)) / 1000)} 秒再试。`;\n } else {\n store.lastFetch[host] = now;\n for (const k of Object.keys(store.lastFetch)) if (now - store.lastFetch[k] > 3600 * 1000) delete store.lastFetch[k];\n }\n}\nconst columns = String($json.columns || '').split(/[、,,;;|\\n]+/).map(s => s.trim()).filter(Boolean).slice(0, 12);\nconst useJina = String($json.mode || '').includes('Jina');\nreturn { json: { url, host, origin, path, robots_url: origin + '/robots.txt', use_jina: useJina, columns, problem } };"},"id":"cb3247ac-6be0-52d5-a6ac-bbfa1a699013","name":"检查网址","type":"n8n-nodes-base.code","typeVersion":2,"position":[-140,160]},{"parameters":{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose","version":2},"conditions":[{"id":"c1","leftValue":"={{ $json.problem }}","rightValue":"","operator":{"type":"string","operation":"empty","singleValue":true}}],"combinator":"and"},"options":{}},"id":"5c07ee6a-b9dd-5a87-83f2-dbd6470dcab1","name":"网址能用吗","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[80,160]},{"parameters":{"url":"={{ $json.robots_url }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"User-Agent","value":"Mozilla/5.0 (compatible; n8n-list-to-table/1.0)"}]},"options":{"timeout":10000,"redirect":{"redirect":{"maxRedirects":5}},"response":{"response":{"fullResponse":true,"neverError":true,"responseFormat":"text"}}}},"id":"c3b15043-534d-580f-9362-2f3ac162851b","name":"读 robots.txt","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[300,60],"onError":"continueRegularOutput"},{"parameters":{"mode":"runOnceForEachItem","jsCode":"// 按 robots.txt 的规矩(RFC 9309)判断这一页能不能抓:最长匹配的规则说了算,一样长时 Allow 优先\nconst BOT = 'n8n-list-to-table';\nconst page = $('检查网址').item.json;\nconst r = $json;\nconst stop = (msg) => ({ json: { ...page, problem: msg } });\nif (r.error) {\n const m = String(r.error.message || r.error.description || JSON.stringify(r.error));\n if (/ENOTFOUND|EAI_AGAIN/.test(m)) return stop('域名解析失败,检查网址有没有拼错。');\n return stop('连不上这个网站(读 robots.txt 时出错:' + m.slice(0, 100) + ')。');\n}\nconst code = Number(r.statusCode || 0);\nif (!code || code >= 500) return stop(`这个网站的 robots.txt 返回 ${code || '空'}。按规矩,读不到 robots.txt 时要当作不让抓,过一会儿再试。`);\nif (code >= 400) return { json: { ...page, problem: '', robots_note: `网站没有 robots.txt(${code}),视为不限制`, crawl_delay: 1 } };\nconst groups = [];\nlet cur = null, lastUA = false;\nfor (let line of String(r.data || '').split(/\\r?\\n/)) {\n line = line.replace(/#.*/, '').trim();\n const i = line.indexOf(':');\n if (!line || i < 0) continue;\n const k = line.slice(0, i).trim().toLowerCase(), v = line.slice(i + 1).trim();\n if (k === 'user-agent') {\n if (!cur || !lastUA) { cur = { agents: [], rules: [], delay: 0 }; groups.push(cur); }\n cur.agents.push(v.toLowerCase()); lastUA = true; continue;\n }\n lastUA = false;\n if (!cur) continue;\n if (k === 'allow' || k === 'disallow') cur.rules.push({ allow: k === 'allow', pat: v });\n if (k === 'crawl-delay' && !isNaN(parseFloat(v))) cur.delay = parseFloat(v);\n}\nconst mine = groups.filter(g => g.agents.some(a => a !== '*' && BOT.includes(a)));\nconst use = mine.length ? mine : groups.filter(g => g.agents.includes('*'));\nconst toRe = (p) => {\n const end = p.endsWith('$');\n const body = (end ? p.slice(0, -1) : p).replace(/[.+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\*/g, '.*');\n return new RegExp('^' + body + (end ? '$' : ''));\n};\nlet best = null;\nfor (const ru of use.flatMap(g => g.rules)) {\n if (!ru.pat) continue;\n let hit = false;\n try { hit = toRe(ru.pat).test(page.path) || toRe(ru.pat).test(decodeURI(page.path)); } catch (e) { hit = toRe(ru.pat).test(page.path); }\n if (hit && (!best || ru.pat.length > best.pat.length || (ru.pat.length === best.pat.length && ru.allow))) best = ru;\n}\nif (best && !best.allow) return stop(`这个网站的 robots.txt 不让抓这一页(规则:Disallow: ${best.pat}),工作流停下了,没有去打开这一页。`);\nconst delay = Math.max(0, ...use.map(g => g.delay || 0));\nconst note = (best ? `robots.txt 允许(Allow: ${best.pat})` : 'robots.txt 没有限制这一页') + (delay ? `,要求两次访问间隔 ${delay} 秒` : '');\nreturn { json: { ...page, problem: '', robots_note: note, crawl_delay: Math.min(Math.max(delay, 1), 10) } };"},"id":"9e86265a-cb8c-5065-8f98-1ecc9300e183","name":"看 robots 让不让抓","type":"n8n-nodes-base.code","typeVersion":2,"position":[520,60]},{"parameters":{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose","version":2},"conditions":[{"id":"c2","leftValue":"={{ $json.problem }}","rightValue":"","operator":{"type":"string","operation":"empty","singleValue":true}}],"combinator":"and"},"options":{}},"id":"2ca7044f-b6db-586e-a17d-b89be3c32d30","name":"robots 让抓吗","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[740,60]},{"parameters":{"resume":"timeInterval","amount":"={{ $json.crawl_delay }}","unit":"seconds"},"id":"45a458bd-4042-57df-8925-95764f875060","name":"按网站要求等一下","type":"n8n-nodes-base.wait","typeVersion":1.1,"position":[960,-40]},{"parameters":{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose","version":2},"conditions":[{"id":"c3","leftValue":"={{ $json.use_jina }}","rightValue":"","operator":{"type":"boolean","operation":"true","singleValue":true}}],"combinator":"and"},"options":{}},"id":"e7bddff5-b6e4-519e-b6a8-d7b874cdd675","name":"用 Jina 吗","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[1180,-40]},{"parameters":{"url":"={{ $json.url }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"User-Agent","value":"Mozilla/5.0 (compatible; n8n-list-to-table/1.0)"},{"name":"Accept-Language","value":"zh-CN,zh;q=0.9,en;q=0.6"}]},"options":{"timeout":20000,"redirect":{"redirect":{"maxRedirects":5}},"response":{"response":{"fullResponse":true,"neverError":true,"responseFormat":"text"}}}},"id":"d016715f-e022-5812-86a4-70fd3d7b27c0","name":"直接抓网页","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1400,60],"onError":"continueRegularOutput"},{"parameters":{"mode":"runOnceForEachItem","jsCode":"// 去掉脚本、样式、导航、页脚和搜索框,把相对链接补成完整网址\nconst r = $json;\nconst page = $('看 robots 让不让抓').item.json;\nconst fail = (msg) => ({ json: { ...page, problem: msg, html: '' } });\nif (r.error) {\n const m = String(r.error.message || r.error.description || JSON.stringify(r.error));\n return fail(/ENOTFOUND|EAI_AGAIN/.test(m) ? '域名解析失败,检查网址有没有拼错。'\n : /timeout|ETIMEDOUT|ECONNABORTED/i.test(m) ? '网页 20 秒没打开,可能是网站太慢,或者跑 n8n 的机器访问不到它。'\n : '网页打不开:' + m.slice(0, 120));\n}\nconst code = Number(r.statusCode || 200);\nif (code === 401 || code === 403) return fail(`网站返回 ${code}:这一页要登录,或者网站不让程序访问。要登录才能看的页面不抓。`);\nif (code === 429) return fail('网站返回 429(访问太频繁)。别连着提交,过一阵再试。');\nif (code >= 400) return fail(`网站返回 ${code},检查网址对不对。`);\nconst ctype = String((r.headers || {})['content-type'] || '');\nif (ctype && !/html|xml|text\\/plain/i.test(ctype)) return fail(`这个地址不是网页(${ctype.split(';')[0]})。`);\nlet html = String(r.data || '');\nif (/<input\\b[^>]*type\\s*=\\s*[\"']?password/i.test(html)) return fail('这一页有密码框,是登录页。要登录才能看的内容不抓。');\nconst pick = (re) => { const m = html.match(re); return m ? m[1].replace(/\\s+/g, ' ').trim() : ''; };\nconst title = pick(/<title[^>]*>([\\s\\S]*?)<\\/title>/i);\n// 补全链接(Code 节点里没有 URL 对象,手写)\nconst base0 = pick(/<base\\b[^>]*href=[\"']([^\"']+)[\"']/i) || page.url;\nconst bm = base0.match(/^(https?):\\/\\/([^\\/?#]+)([^?#]*)/i) || page.url.match(/^(https?):\\/\\/([^\\/?#]+)([^?#]*)/i);\nconst proto = bm[1].toLowerCase(), origin = proto + '://' + bm[2], basePath = bm[3] || '/';\nconst abs = (h) => {\n h = h.trim().replace(/&/g, '&');\n if (!h || h.startsWith('#') || /^(javascript|mailto|tel|data):/i.test(h)) return '';\n if (/^https?:\\/\\//i.test(h)) return h;\n if (h.startsWith('//')) return proto + ':' + h;\n if (h.startsWith('/')) return origin + h;\n if (h.startsWith('?')) return origin + basePath + h;\n const parts = (basePath.replace(/[^\\/]*$/, '') + h).split('/');\n const out = [];\n for (const p of parts) { if (p === '..') { if (out.length > 1) out.pop(); } else if (p !== '.') out.push(p); }\n return origin + out.join('/');\n};\nhtml = html.replace(/<!--[\\s\\S]*?-->/g, '')\n .replace(/<(script|style|noscript|svg|iframe|template|canvas|nav|footer|form|select)\\b[\\s\\S]*?<\\/\\1>/gi, '')\n .replace(/<(link|meta|input|base)\\b[^>]*>/gi, '')\n .replace(/\\s(style|class|id|data-[\\w-]+|on\\w+|target|rel)=(\"[^\"]*\"|'[^']*')/gi, '');\nconst links = [];\nhtml = html.replace(/\\s(href|src)\\s*=\\s*([\"'])([\\s\\S]*?)\\2/gi, (all, attr, q, v) => {\n const u = abs(v);\n if (attr.toLowerCase() === 'href' && u) links.push(u);\n return u ? ` ${attr}=\"${u.replace(/\"/g, '%22')}\"` : '';\n});\nreturn { json: { ...page, problem: '', title, html, links, via: 'n8n 直接抓' } };"},"id":"f263590d-eed7-51ac-a44b-94cda600bd8f","name":"整理网页","type":"n8n-nodes-base.code","typeVersion":2,"position":[1620,60]},{"parameters":{"html":"={{ $json.html }}","destinationKey":"page_text","options":{}},"id":"a3d5277c-8dfa-5da3-8d2b-6b4e7f443133","name":"转成文字","type":"n8n-nodes-base.markdown","typeVersion":1,"position":[1840,60]},{"parameters":{"url":"=https://r.jinaai.cn/{{ $json.url }}","sendHeaders":true,"headerParameters":{"parameters":[{"name":"DNT","value":"1"},{"name":"X-Robots-Txt","value":"n8n-list-to-table"},{"name":"X-Respond-With","value":"markdown"},{"name":"X-Timeout","value":"20"}]},"options":{"timeout":60000,"redirect":{"redirect":{"maxRedirects":5}},"response":{"response":{"fullResponse":true,"neverError":true,"responseFormat":"text"}}}},"id":"03ac26fc-ad4b-53df-b860-c6ffba837611","name":"Jina 代抓","type":"n8n-nodes-base.httpRequest","typeVersion":4.2,"position":[1400,-180],"onError":"continueRegularOutput"},{"parameters":{"mode":"runOnceForEachItem","jsCode":"// Jina 返回的已经是 Markdown,链接是完整网址;去掉它加的头几行\nconst r = $json;\nconst page = $('看 robots 让不让抓').item.json;\nconst fail = (msg) => ({ json: { ...page, problem: msg, page_text: '' } });\nif (r.error) return fail('连不上 Jina:' + String(r.error.message || JSON.stringify(r.error)).slice(0, 120) + '。可以换回「n8n 直接抓」。');\nconst code = Number(r.statusCode || 200);\nlet text = String(r.data || '');\nif (code >= 400) return fail(`Jina 返回 ${code}:` + text.replace(/\\s+/g, ' ').slice(0, 200));\nconst t = text.match(/^Title:\\s*(.*)$/m);\nconst i = text.indexOf('Markdown Content:');\nif (i >= 0) text = text.slice(i + 'Markdown Content:'.length);\nconst links = [...text.matchAll(/\\]\\((https?:\\/\\/[^)\\s]+)/g)].map(m => m[1]);\nreturn { json: { ...page, problem: '', title: t ? t[1].trim() : '', page_text: text.trim(), links, via: 'Jina Reader' } };"},"id":"6adb600f-6ae8-511c-8811-6c0507638ff1","name":"整理 Jina 结果","type":"n8n-nodes-base.code","typeVersion":2,"position":[1620,-180]},{"parameters":{"mode":"runOnceForEachItem","jsCode":"// 靠 JavaScript 加载的页面,直接抓只能拿到空壳\nconst MAX_CHARS = 20000; // 太长的页面只看前 20000 个字,防止一次花太多钱\nconst MIN_CHARS = 80; // 少于 80 个字就当作空壳,不调模型\nif ($json.problem) return { json: $json };\n// 转 Markdown 时链接里的 _ 和 * 被写成了 %5F、%2A,改回来,表格里的链接才和原网页一样\nlet text = String($json.page_text || '').replace(/\\]\\(([^)\\s]*)/g, (m, u) => '](' + u.replace(/%5F/gi, '_').replace(/%2A/gi, '*'))\n .replace(/\\n{3,}/g, '\\n\\n').trim();\nconst plain = text.replace(/!?\\[([^\\]]*)\\]\\([^)]*\\)/g, '$1').replace(/[#>*_`|\\-\\s]/g, '');\nif (plain.length < MIN_CHARS) {\n return { json: { ...$json, problem: $json.via === 'Jina Reader'\n ? `Jina 也只抓到 ${plain.length} 个字,这一页可能要登录,或者网站挡住了 Jina。`\n : `抓到的是空壳:网页源代码里只有 ${plain.length} 个字,列表应该是打开后才用 JavaScript 加载的。可以把「抓取方式」换成 Jina Reader 再试(网址会发给 Jina)。` } };\n}\nconst cut = text.length > MAX_CHARS;\nif (cut) text = text.slice(0, MAX_CHARS);\nreturn { json: { ...$json, page_text: text, chars: plain.length, cut } };"},"id":"67d6d7d7-4359-5482-bf5f-1852ac6fb8bb","name":"看看抓到了多少","type":"n8n-nodes-base.code","typeVersion":2,"position":[2060,-60]},{"parameters":{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose","version":2},"conditions":[{"id":"c4","leftValue":"={{ $json.problem }}","rightValue":"","operator":{"type":"string","operation":"empty","singleValue":true}}],"combinator":"and"},"options":{}},"id":"70eec323-97f1-53c0-a12e-0ab9e1eeabc4","name":"内容够不够","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[2280,-60]},{"parameters":{"promptType":"define","text":"=你是做数据整理的助手。下面是一个网页的文字版(程序从网页转出来的 Markdown,链接都已经是完整网址)。请把网页上「主列表」里的每一条整理成表格的一行。\n\n【要哪几列】\n{{ $json.columns.length ? $json.columns.join('、') : '没指定。请按页面内容自己定 3~6 列:第一列是这一条的名称或标题,最后一列是这一条的链接,中间放页面上每条都有的信息(比如价格、日期、地点)。列名用中文。' }}\n\n【规矩】\n1. 只抄网页上写着的内容:可以去掉多余的空格和换行,不改写、不翻译、不换算、不补全。页面上没有的就填空字符串 \"\",不许猜。\n2. 「链接」这类列,填这一条自己的详情链接(Markdown 里 ](...) 括号中的网址),不要填分类、翻页、广告的链接。\n3. 只整理主列表。导航栏、页脚、侧栏推荐、「猜你喜欢」、广告、推广、翻页按钮都不要。\n4. 同一条在页面上出现好几次(比如电脑版、手机版各一个链接),只算一行。\n5. 按页面上的先后顺序,页面上有多少条就输出多少行,一条都不要漏。\n6. 不抄个人信息:个人的手机号、邮箱、微信号、QQ 号、身份证号、住址,就算要的列里有,也填 \"\"。\n{{ $json.cut ? '7. 网页太长,下面只给了前面一部分,最后一条可能不完整,不完整的那一条不要输出。' : '' }}\n\n【输出格式】\n只输出一个 JSON 对象,不要用 ``` 包起来,前后不要加别的文字:\n{\"columns\": [\"列名1\", \"列名2\"], \"rows\": [[\"第一条的列1\", \"第一条的列2\"]], \"note\": \"一句话:页面上一共看到多少条,有没有拿不准的地方\"}\nrows 里每一行的值和 columns 一一对应,全部写成字符串。\n\n【网页信息】\n网址:{{ $json.url }}\n网页标题:{{ $json.title || '(没有)' }}\n\n【网页文字】\n{{ $json.page_text }}","batching":{}},"id":"3dd42b11-fa08-5c1b-ba03-b6a7b0f00404","name":"AI 整理成表格","type":"@n8n/n8n-nodes-langchain.chainLlm","typeVersion":1.7,"position":[2500,-160],"retryOnFail":true,"maxTries":2,"waitBetweenTries":3000,"onError":"continueErrorOutput"},{"parameters":{"model":"deepseek-flash","options":{}},"id":"74a028ae-7367-54a6-98b2-d85324916373","name":"模型","type":"@n8n/n8n-nodes-langchain.lmChatDeepSeek","typeVersion":1,"position":[2500,60]},{"parameters":{"mode":"runOnceForEachItem","jsCode":"// 程序核对:AI 填的每个格子都回原文里找一遍,找不到的标出来;再去掉手机号、邮箱、微信号、身份证号\nconst page = $('内容够不够').item.json;\nconst esc = (s) => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\"/g, '"');\nlet raw = String($json.text || '').trim().replace(/^```(?:json)?\\s*/i, '').replace(/```\\s*$/, '');\nlet data = null;\ntry { data = JSON.parse(raw.slice(raw.indexOf('{'), raw.lastIndexOf('}') + 1)); } catch (e) {}\nif (!data || !Array.isArray(data.rows) || !Array.isArray(data.columns) || !data.columns.length) {\n return { json: { ok: false, problem: 'AI 返回的内容不是表格格式。再提交一次试试;还不行就打开 n8n 的 Executions 看「AI 整理成表格」的输出。' + raw.slice(0, 150) } };\n}\nconst cols = data.columns.map(c => String(c).trim() || '列');\nconst norm = (s) => String(s || '').toLowerCase().replace(/&/g, '&').replace(/ /g, ' ').replace(/[\\s *_`#>|\\\\]/g, '');\nconst pageText = String(page.page_text || '');\nconst textN = norm(pageText.replace(/\\]\\([^)]*\\)/g, ']'));\nconst linkKey = (u) => String(u).replace(/#.*$/, '').replace(/%28/gi, '(').replace(/%29/gi, ')').replace(/%5F/gi, '_').replace(/%2A/gi, '*');\nconst linkSet = new Set((page.links || []).map(linkKey));\nfor (const m of pageText.matchAll(/\\]\\((https?:\\/\\/[^)\\s]+)/g)) linkSet.add(linkKey(m[1]));\nlet masked = 0;\nconst hide = (label) => () => { masked++; return `[${label}已去掉]`; };\nconst mask = (s) => /^https?:\\/\\/\\S+$/i.test(s) ? s : s\n .replace(/(?<![\\dA-Za-z])1[3-9]\\d[\\s-]?\\d{4}[\\s-]?\\d{4}(?![\\dA-Za-z])/g, hide('手机号'))\n .replace(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}/g, hide('邮箱'))\n .replace(/(?<![\\dA-Za-z])\\d{17}[\\dXx](?![\\dA-Za-z])/g, hide('身份证号'))\n .replace(/(微信号?|wechat|weixin|vx|QQ号?)\\s*[::]?\\s*[A-Za-z0-9_-]{5,}/gi, (m, k) => { masked++; return k + '[已去掉]'; });\nconst seen = new Set();\nconst rows = [];\nlet dup = 0, unmatched = 0;\nfor (const r0 of data.rows) {\n const arr = Array.isArray(r0) ? r0 : cols.map(c => (r0 || {})[c]);\n const cells = cols.map((c, i) => String(arr[i] ?? '').replace(/\\s+/g, ' ').trim());\n const key = cells.join('\\u0001');\n if (!cells.some(Boolean) || seen.has(key)) { dup++; continue; }\n seen.add(key);\n const miss = [];\n cells.forEach((v, i) => {\n if (!v) return;\n if (/^https?:\\/\\//i.test(v)) { if (!linkSet.has(linkKey(v))) miss.push(/链接|网址|url/i.test(cols[i]) ? cols[i] : cols[i] + '(链接)'); }\n else if (!textN.includes(norm(v))) {\n // 几段拼起来的(比如多个标签用逗号连起来),拆开后每段都在原文里也算对得上\n const parts = v.split(/\\s*[,,、;;|\\/]\\s*/).filter(Boolean);\n if (!(parts.length > 1 && parts.every(p => textN.includes(norm(p))))) miss.push(cols[i]);\n }\n });\n if (miss.length) unmatched++;\n const row = { '序号': rows.length + 1 };\n cols.forEach((c, i) => { row[c] = mask(cells[i]); });\n row['核对'] = miss.length ? '原文里没找到:' + miss.join('、') : '对得上';\n rows.push(row);\n}\nif (!rows.length) return { json: { ok: false, problem: 'AI 没从这一页整理出任何一条。可能这一页不是列表页,或者列表要翻页、点击才出来。' } };\nconst SHOW = 100;\nconst head = ['序号', ...cols, '核对'];\nconst cell = (k, v) => {\n const s = String(v ?? '');\n if (/^https?:\\/\\//i.test(s)) return `<a href=\"${esc(s)}\" target=\"_blank\" rel=\"noopener\">${esc(s.length > 60 ? s.slice(0, 57) + '…' : s)}</a>`;\n if (k === '核对' && s !== '对得上') return `<strong>${esc(s)}</strong>`;\n return esc(s);\n};\nconst table = '<table><thead><tr>' + head.map(h => `<th>${esc(h)}</th>`).join('') + '</tr></thead><tbody>'\n + rows.slice(0, SHOW).map(r => '<tr>' + head.map(h => `<td>${cell(h, r[h])}</td>`).join('') + '</tr>').join('') + '</tbody></table>';\nconst facts = [\n `网址:${esc(page.url)}`,\n `抓取方式:${esc(page.via)};${esc(page.robots_note || '')}`,\n `整理出 <strong>${rows.length}</strong> 条` + (dup ? `(去掉重复 ${dup} 条)` : '') + (unmatched ? `,其中 <strong>${unmatched}</strong> 条有格子在原文里没找到,看「核对」一列` : ',每个格子都在原文里找到了')\n + (masked ? `;去掉了 ${masked} 处个人联系方式` : ''),\n page.cut ? '页面太长,只看了前 20000 个字,后面的条目没有抓。' : '',\n data.note ? `AI 的备注:${esc(data.note)}` : '',\n rows.length > SHOW ? `这里只显示前 ${SHOW} 条,下载的 Excel 里是全部。` : '',\n].filter(Boolean);\nconst html = '<div>' + facts.map(f => `<p>${f}</p>`).join('') + '</div>' + table\n + '<p>AI 整理的表格可能漏条、抄错,用之前对着原网页抽查几条。抓来的内容版权归原网站,别拿去整页转载。</p>';\nconst date = $now.setZone('Asia/Shanghai').toFormat('yyyyMMdd-HHmm');\nreturn { json: { ok: true, html, rows, count: rows.length, file_name: `列表-${page.host}-${date}.xlsx` } };"},"id":"438d334c-5f7d-5c99-ad1c-4126be37808d","name":"核对和去个人信息","type":"n8n-nodes-base.code","typeVersion":2,"position":[2760,-160]},{"parameters":{"conditions":{"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose","version":2},"conditions":[{"id":"c5","leftValue":"={{ $json.ok }}","rightValue":"","operator":{"type":"boolean","operation":"true","singleValue":true}}],"combinator":"and"},"options":{}},"id":"979e0dd5-4d49-5376-a673-8fc850c93683","name":"整理好了吗","type":"n8n-nodes-base.if","typeVersion":2.2,"position":[2980,-160]},{"parameters":{"operation":"page","defineForm":"json","jsonOutput":"={{ JSON.stringify([{ fieldType: 'html', html: $json.html }]) }}","options":{"formTitle":"抓到的表格","buttonLabel":"下载 Excel 表格","customCss":":root { --container-width: 1100px; --font-family: -apple-system, \"PingFang SC\", \"Microsoft YaHei\", \"Noto Sans CJK SC\", sans-serif; --font-size-paragraph: 14px; --color-submit-btn-bg: #1f7a5a; }\ntable { border-collapse: collapse; width: 100%; font-size: 13px; margin: 8px 0 12px; }\nth, td { border: 1px solid #dcdfe6; padding: 5px 8px; text-align: left; vertical-align: top; }\nth { background: #f2f5f3; white-space: nowrap; }\ntd strong { color: #c0392b; }"}},"id":"052ae440-17bf-5bb9-b66b-49e272384c35","name":"看结果","type":"n8n-nodes-base.form","typeVersion":2.5,"position":[3200,-260]},{"parameters":{"jsCode":"// 把表格拆成一行一条,交给下一步生成 Excel\nreturn $('核对和去个人信息').first().json.rows.map(r => ({ json: r }));"},"id":"d2ac95a3-2f70-5d9b-95df-a6408d5bdaa2","name":"一行一条","type":"n8n-nodes-base.code","typeVersion":2,"position":[3420,-260]},{"parameters":{"operation":"xlsx","binaryPropertyName":"data","options":{"fileName":"={{ $('核对和去个人信息').first().json.file_name }}","sheetName":"抓取结果","headerRow":true}},"id":"dd73693c-2902-5c17-b09f-1ee75000b2a2","name":"转成 Excel","type":"n8n-nodes-base.convertToFile","typeVersion":1.1,"position":[3640,-260]},{"parameters":{"operation":"completion","respondWith":"returnBinary","inputDataFieldName":"data","completionTitle":"表格已经下载","completionMessage":"=文件名:{{ $('核对和去个人信息').first().json.file_name }}。浏览器没自动下载的话,在 n8n 里打开这个工作流,点顶部的 Executions 找到这次执行,在「转成 Excel」节点的输出里也能下载。","options":{}},"id":"17207e74-e83f-5a34-98d7-3a0f582a8932","name":"下载表格","type":"n8n-nodes-base.form","typeVersion":2.5,"position":[3860,-260]},{"parameters":{"operation":"completion","completionTitle":"这一页没有抓","completionMessage":"={{ $json.problem }}","options":{}},"id":"ddf18b99-3522-5619-9dec-45e2bb4a0a91","name":"没法抓","type":"n8n-nodes-base.form","typeVersion":2.5,"position":[2500,400]},{"parameters":{"operation":"completion","completionTitle":"没整理出表格","completionMessage":"={{ $json.problem }}","options":{}},"id":"4721c08a-181e-5a7e-8dbb-a3306066345f","name":"没整理出来","type":"n8n-nodes-base.form","typeVersion":2.5,"position":[3200,-40]},{"parameters":{"operation":"completion","completionTitle":"AI 这次没答上来","completionMessage":"=模型接口报错:{{ String($json.error?.message || $json.error || '未知错误').slice(0, 300) }}。常见原因是 API Key 填错、账户余额不足、模型名写错,或者网页太长。过一会儿再试,还不行就打开 n8n 的 Executions 看这次执行的详细报错。","options":{}},"id":"716272ce-642f-53f4-9229-4bf586a9db1a","name":"AI 没答上来","type":"n8n-nodes-base.form","typeVersion":2.5,"position":[2760,60]}],"connections":{"填网址":{"main":[[{"node":"检查网址","type":"main","index":0}]]},"检查网址":{"main":[[{"node":"网址能用吗","type":"main","index":0}]]},"网址能用吗":{"main":[[{"node":"读 robots.txt","type":"main","index":0}],[{"node":"没法抓","type":"main","index":0}]]},"读 robots.txt":{"main":[[{"node":"看 robots 让不让抓","type":"main","index":0}]]},"看 robots 让不让抓":{"main":[[{"node":"robots 让抓吗","type":"main","index":0}]]},"robots 让抓吗":{"main":[[{"node":"按网站要求等一下","type":"main","index":0}],[{"node":"没法抓","type":"main","index":0}]]},"按网站要求等一下":{"main":[[{"node":"用 Jina 吗","type":"main","index":0}]]},"用 Jina 吗":{"main":[[{"node":"Jina 代抓","type":"main","index":0}],[{"node":"直接抓网页","type":"main","index":0}]]},"直接抓网页":{"main":[[{"node":"整理网页","type":"main","index":0}]]},"整理网页":{"main":[[{"node":"转成文字","type":"main","index":0}]]},"Jina 代抓":{"main":[[{"node":"整理 Jina 结果","type":"main","index":0}]]},"转成文字":{"main":[[{"node":"看看抓到了多少","type":"main","index":0}]]},"整理 Jina 结果":{"main":[[{"node":"看看抓到了多少","type":"main","index":0}]]},"看看抓到了多少":{"main":[[{"node":"内容够不够","type":"main","index":0}]]},"内容够不够":{"main":[[{"node":"AI 整理成表格","type":"main","index":0}],[{"node":"没法抓","type":"main","index":0}]]},"模型":{"ai_languageModel":[[{"node":"AI 整理成表格","type":"ai_languageModel","index":0}]]},"AI 整理成表格":{"main":[[{"node":"核对和去个人信息","type":"main","index":0}],[{"node":"AI 没答上来","type":"main","index":0}]]},"核对和去个人信息":{"main":[[{"node":"整理好了吗","type":"main","index":0}]]},"整理好了吗":{"main":[[{"node":"看结果","type":"main","index":0}],[{"node":"没整理出来","type":"main","index":0}]]},"看结果":{"main":[[{"node":"一行一条","type":"main","index":0}]]},"一行一条":{"main":[[{"node":"转成 Excel","type":"main","index":0}]]},"转成 Excel":{"main":[[{"node":"下载表格","type":"main","index":0}]]}},"settings":{"executionOrder":"v1","timezone":"Asia/Shanghai","saveManualExecutions":true},"pinData":{},"meta":{"templateCredsSetupCompleted":false}}
下载后在 n8n、Dify 里导入;n8n 也可以直接在画布上按 Ctrl+V 粘贴。