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": []
}
相关推荐
無间行者3 天前
【笔记】n8n 自动化平台安装部署使用笔记(一)
自动化流程·n8n
無间行者3 天前
【笔记】n8n 新手上路指南(三)
自动化流程·n8n
無间行者4 天前
【笔记】n8n Docker 容器时间与时区同步记录(二)
自动化流程·n8n
HoldBelief6 天前
安装N8N2.11.2 以及 访问宿主机上的文件
n8n
一马平川的大草原1 个月前
基于n8n构建企业内部知识库
人工智能·知识库·n8n
勇气要爆发1 个月前
2026年想学AI,面对 Dify、Coze、n8n、LangChain 该学哪个?
人工智能·langchain·dify·coze·n8n
呆萌的代Ma1 个月前
N8N(二):示例项目:将表单内容写入到飞书表格中
大模型·飞书·n8n
呆萌的代Ma1 个月前
N8N(一):在Docker中安装N8N
docker·容器·n8n
rs勿忘初心1 个月前
n8n工作流使用问题集合
常见问题·n8n·工作流平台·json解析方法·json参数报错
m_136871 个月前
n8n 启动时报 EACCES permission denied 的完整排查与修复
自动化·n8n