n8n,rss网页抓新闻发邮件

参考来源: https://zhuanlan.zhihu.com/p/1960097445301170903 , 此处仅为记录中间过程。

一 功能

读取网页的新闻,利用大模型进行总结,生成新的html页面,通过邮件定时发送

二 整体工作流截图

三 各个节点介绍

3.1 定时触发节点

3.2 rss节点

读取页面内容

3.3 编辑字段

去掉不需要的节点

3.4 模型链,使用deepseek

提示词

javascript 复制代码
你现在是一个文本总结专家,我会给你一篇文章的标题和正文,你需要总结这个文章。注意,你只能输出总结的内容,不能包含类似"下面是文章总结后的内容..."等等提示词。

文章标题: {{ $json['标题'] }}

文章正文:{{ $json['正文'] }}

3.5 编辑字段

将分类和新闻数据连在一起

3.6 过滤节点

3.6.1 编辑字段

3.6.2 大模型 -> 编辑字段

3.6.3 编辑字段

同3.6.1

3.6.4 编辑字段

同3.6.1

3.7 merge节点

3.8 聚合节点

3.9 code节点

code如下:

javascript 复制代码
function getnews(dataArray) {
  let html = "";
  dataArray.forEach((item, index) => {
    let source = "IT之家";
    html += "来源:";
    html += source;
    html += ";链接:";
    html += item.链接;
    html += ";标题:";
    html += item.标题;
    html += ";正文:";
    html += item.正文;
    html += ";分类:";
    html += item.分类;
    html += "|一条新闻结束|";
  })
  return html;
}

3.10 模型链节点(deepseek)

模型的提示词:

python 复制代码
你现在是一个网页生成专家,我会给你一些新闻列表,你需要返回一个介绍这些新闻的html,要求包含原文链接,总结,分类,标题。

你只能输出html文本,不能输出其他任何提示词,也不能包括其他任何内容,你只能输出html代码,不能输出其他内容。 也不用输出包括代码的代码块(```)

这是新闻列表:{{ $json.html }}

3.11 发送邮件

邮件的subject:今日({{ ('定时触发').item.json\['Day of month'\] }}{{ ('定时触发').item.json.Month }}{{ $('定时触发').item.json.Year }}) 新闻总结

打开邮件,看到收件箱

四 工作流json文件

请注意将最后一个邮箱节点,填入自己的邮箱凭证,并替换成自己的邮箱

新建一个工作流,直接Ctrl + V即可

cpp 复制代码
{
  "name": "My workflow",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatDeepSeek",
      "typeVersion": 1,
      "position": [
        56,
        852
      ],
      "id": "9044066b-bb6d-487a-b053-e75c8f3d2c4c",
      "name": "DeepSeek Chat Model",
      "credentials": {
        "deepSeekApi": {
          "id": "94mTOHKtmAduCqzW",
          "name": "DeepSeek account"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "0e1111ab-3908-4f4b-b2aa-e5c88626b494",
              "name": "标题",
              "value": "={{ $('去掉无关信息').item.json['标题'] }}",
              "type": "string"
            },
            {
              "id": "b3150e2d-b7d3-4dd8-b90c-4a217dd182ea",
              "name": "链接",
              "value": "={{ $('去掉无关信息').item.json['链接'] }}",
              "type": "string"
            },
            {
              "id": "9ed47583-09c7-4d37-8839-c61c0fb2e30c",
              "name": "正文",
              "value": "={{ $('去掉无关信息').item.json['正文'] }}",
              "type": "string"
            },
            {
              "id": "7aae1ffa-18ba-4b70-8c6f-0e852126b08e",
              "name": "分类",
              "value": "={{ $json.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        336,
        628
      ],
      "id": "3f638cd4-8cd7-435a-835d-47b20936b0f2",
      "name": "拼接标签和内容"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=你现在是一个文本总结专家,我会给你一篇文章的标题和正文,你需要总结这个文章。注意,你只能输出总结的内容,不能包含类似"下面是文章总结后的内容..."等等提示词。\n\n文章标题: {{ $json['标题'] }}\n\n文章正文:{{ $json['正文'] }}",
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        784,
        504
      ],
      "id": "61ed39ed-34f3-4d26-8e7e-6d12ba3a12c5",
      "name": "总结内容"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatDeepSeek",
      "typeVersion": 1,
      "position": [
        856,
        728
      ],
      "id": "a0548076-06f2-499f-911b-51e26e6fbc0c",
      "name": "DeepSeek Chat Model1",
      "credentials": {
        "deepSeekApi": {
          "id": "94mTOHKtmAduCqzW",
          "name": "DeepSeek account"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=你现在是一个分类器,你需要分类文章。我将会给你文章的标题,你需要将文章分为以下几类\n\n广告, 科技, 设备,大公司变化, 产品漏洞, 加密货币, 日常杂事, 大人物发言等\n\n请只输出标签的名字,其他什么都不要输出。这是文章标题: {{ $json['标题'] }}",
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        -16,
        628
      ],
      "id": "59d0db12-8846-49ab-a538-c6a9ec3db3df",
      "name": "分类文章标签"
    },
    {
      "parameters": {
        "url": "https://www.ithome.com/rss/",
        "options": {}
      },
      "type": "n8n-nodes-base.rssFeedRead",
      "typeVersion": 1.2,
      "position": [
        -464,
        628
      ],
      "id": "ed50923d-7bf2-4142-9d7e-79902938c080",
      "name": "拉取文章"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "9aebd36a-3810-4428-8c27-1b0181dd1e27",
              "name": "标题",
              "value": "={{ $json['标题'] }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1136,
        256
      ],
      "id": "857629e8-1e20-40b7-8cc1-3bd86ba7cf95",
      "name": "只留标题"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "8011ccc4-3284-43ad-abb0-f5991e525b26",
              "name": "链接",
              "value": "={{ $json['链接'] }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1136,
        752
      ],
      "id": "664d6bda-5262-4f8a-8712-be71f663040f",
      "name": "只留链接"
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "numberInputs": 4,
        "options": {}
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        1360,
        596
      ],
      "id": "3aa88247-1d05-4cab-9e1c-8c5f572c8e37",
      "name": "Merge",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "442617c4-0155-4e07-8568-973d1871c224",
              "name": "分类",
              "value": "={{ $json['分类'] }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1136,
        944
      ],
      "id": "c725ee25-6cd4-4d35-8920-8d7fba8bd749",
      "name": "只留分类"
    },
    {
      "parameters": {
        "content": "## Power by opzc35\n\n## 参照https://linux.do/t/topic/583107 编写,优化部分内容\n",
        "width": 544
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -64,
        -64
      ],
      "id": "0ab12962-112d-4141-bd7f-ab6820af974d",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=你现在是一个网页生成专家,我会给你一些新闻列表,你需要返回一个介绍这些新闻的html,要求包含原文链接,总结,分类,标题。\n\n你只能输出html文本,不能输出其他任何提示词,也不能包括其他任何内容,你只能输出html代码,不能输出其他内容。 也不用输出包括代码的代码块(```)\n\n这是新闻列表:{{ $json.html }}",
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        2032,
        628
      ],
      "id": "65ed4710-84ec-4044-9810-d817dce2c052",
      "name": "让AI生成优美的总结",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "options": {}
      },
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        1584,
        628
      ],
      "id": "54469301-0860-44e4-9d58-d1659199fad6",
      "name": "将信息整合"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "08eb3ebd-0865-479e-a8db-c46ed9f0f6b1",
              "name": "正文",
              "value": "={{ $json.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1136,
        504
      ],
      "id": "66cfb166-d195-4b17-b172-533647a8c152",
      "name": "重命名变量"
    },
    {
      "parameters": {
        "options": {
          "timeout": 2147483647
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatDeepSeek",
      "typeVersion": 1,
      "position": [
        2104,
        852
      ],
      "id": "75febbef-82c8-4b08-a1b5-ad64683d1d6d",
      "name": "DeepSeek Chat Model2",
      "credentials": {
        "deepSeekApi": {
          "id": "94mTOHKtmAduCqzW",
          "name": "DeepSeek account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// 获取输入数据\nconst inputData = items[0].json.data;\n\nfunction getnews(dataArray) {\n  let html = \"\";\n  dataArray.forEach((item, index) => {\n    let source = \"IT之家\";\n    html += \"来源:\";\n    html += source;\n    html += \";链接:\";\n    html += item.链接;\n    html += \";标题:\";\n    html += item.标题;\n    html += \";正文:\";\n    html += item.正文;\n    html += \";分类:\";\n    html += item.分类;\n    html += \"|一条新闻结束|\";\n  })\n  return html;\n}\n\nconst newslist = getnews(inputData);\nreturn {\n    json: {\n        html: newslist\n    }\n}"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1808,
        628
      ],
      "id": "0d0367ae-8725-401f-98d1-b962e4bd124c",
      "name": "Code in JavaScript",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "fromEmail": "aaaa@qq.com",
        "toEmail": "aaaa@qq.com",
        "subject": "=今日({{ $('定时触发').item.json['Day of month'] }}{{ $('定时触发').item.json.Month }}{{ $('定时触发').item.json.Year }}) 新闻总结",
        "html": "={{ $json.text }}",
        "options": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        2384,
        628
      ],
      "id": "3cac7ee7-fb59-4891-8ab5-c4f4f45d2db0",
      "name": "发送邮件",
      "webhookId": "96d01e62-e433-4669-b756-1662da8b9667",
      "credentials": {
        "smtp": {
          "id": "mBM9pFoO2ZyWqEr1",
          "name": "SMTP account"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 13,
              "triggerAtMinute": 45
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -688,
        628
      ],
      "id": "ea634c87-95de-47a4-ae40-739e555b5271",
      "name": "定时触发"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "facee56e-4c55-4e17-9f37-c649fab3521e",
              "name": "标题",
              "value": "={{ $json.title }}",
              "type": "string"
            },
            {
              "id": "5139b548-aaf6-443f-aa75-c6e763d44d7f",
              "name": "链接",
              "value": "={{ $json.link }}",
              "type": "string"
            },
            {
              "id": "fdf46b0e-58b7-4e7e-a205-632e5c798b41",
              "name": "正文",
              "value": "={{ $json.contentSnippet }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -240,
        628
      ],
      "id": "88f22e30-51b4-4fb1-955f-7b07e7d01f0f",
      "name": "去掉无关信息"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "c0d9a921-3bf6-4d62-851a-477753ea56ad",
              "leftValue": "={{ $json['分类'] }}",
              "rightValue": "广告",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        560,
        628
      ],
      "id": "65b6ce58-b296-453c-bb70-6481f4ebe7ca",
      "name": "filter广告"
    }
  ],
  "pinData": {},
  "connections": {
    "DeepSeek Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "分类文章标签",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "拼接标签和内容": {
      "main": [
        [
          {
            "node": "filter广告",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "总结内容": {
      "main": [
        [
          {
            "node": "重命名变量",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DeepSeek Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "总结内容",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "分类文章标签": {
      "main": [
        [
          {
            "node": "拼接标签和内容",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "拉取文章": {
      "main": [
        [
          {
            "node": "去掉无关信息",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "只留标题": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "只留链接": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "将信息整合",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "只留分类": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 3
          }
        ]
      ]
    },
    "让AI生成优美的总结": {
      "main": [
        [
          {
            "node": "发送邮件",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "将信息整合": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "重命名变量": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "DeepSeek Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "让AI生成优美的总结",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "让AI生成优美的总结",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "定时触发": {
      "main": [
        [
          {
            "node": "拉取文章",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "去掉无关信息": {
      "main": [
        [
          {
            "node": "分类文章标签",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "filter广告": {
      "main": [
        [
          {
            "node": "只留标题",
            "type": "main",
            "index": 0
          },
          {
            "node": "总结内容",
            "type": "main",
            "index": 0
          },
          {
            "node": "只留链接",
            "type": "main",
            "index": 0
          },
          {
            "node": "只留分类",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "availableInMCP": false
  },
  "versionId": "4e76982c-64b6-49e8-bfdb-2106923d3df6",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "9ad7d7448b9dbc9e748ad36fbb0e418d4f6ced72fc091f2f6618c78c54ef265b"
  },
  "id": "BjNbBe2bC52C-6Y8mpcBr",
  "tags": []
}
相关推荐
特立独行的猫a1 天前
告别碎片化笔记:基于n8n-mcp的AI写作助手实战
人工智能·笔记·ai写作·n8n·n8n-mcp
特立独行的猫a1 天前
告别写作焦虑:用 n8n + AI 打造“输入即发布”的自驱动写作工作流
人工智能·工作流·n8n
Benny的老巢2 天前
【n8n工作流入门01】n8n工作流自动化平台架构解析与核心概念详解
数据流·n8n·n8n工作流·工作流自动化·自动化开发
Benny的老巢2 天前
【n8n工作流入门02】macOS安装n8n保姆级教程:Homebrew与npm两种方式详解
macos·npm·node.js·n8n·n8n工作流·homwbrew·n8n安装
xiao5kou4chang6kai43 天前
贯通LLM应用→数据分析→自动化编程→文献及知识管理→科研写作与绘图→构建本地LLM、Agent→多模型圆桌会议→N8N自动化工作流深度应用
人工智能·自动化·llm·科研绘图·n8n
cyzat3213 天前
n8n 2.0 深度解析:从开发工具到企业级自动化平台的华丽
运维·自动化·n8n·企业级平台
Benny的老巢4 天前
n8n工作流通过Execute Command用FFmpeg处理音频,报错 stderr maxBuffer length exceeded的解决方案
ffmpeg·音频合成·n8n·n8n工作流·execute command
yubin12774086294 天前
n8n:rag、钉钉机器人
n8n
Benny的老巢4 天前
Docker环境n8n连接Chrome DevTools Protocol的操作方法
docker·chrome devtools·ai agent·n8n·n8n工作流