_Gmail_データを抽出
中級
これはDocument Extraction分野の自動化ワークフローで、15個のノードを含みます。主にSet, Code, Html, Gmail, HttpRequestなどのノードを使用。 Gmailリンクからウェブデータを抽出し、Googleシートに保存
前提条件
- •Googleアカウント + Gmail API認証情報
- •ターゲットAPIの認証情報が必要な場合あり
- •Google Sheets API認証情報
カテゴリー
ワークフロープレビュー
ノード接続関係を可視化、ズームとパンをサポート
ワークフローをエクスポート
以下のJSON設定をn8nにインポートして、このワークフローを使用できます
{
"id": "t5hsHZLvrxN168ug",
"meta": {
"instanceId": "42efbf5091f345f6cdcec395a521a7e26a4b0772e8643c5c7c8ffc8467c1089c"
},
"name": "Extraindo_Dados_Gmail",
"tags": [],
"nodes": [
{
"id": "996ac1ec-c471-4734-a82c-c44c16ce74ad",
"name": "「Test workflow」クリック時",
"type": "n8n-nodes-base.manualTrigger",
"position": [
-1728,
-400
],
"parameters": {},
"typeVersion": 1
},
{
"id": "8473c056-35d1-4e47-96dd-e0cb30e14ad1",
"name": "メール検索",
"type": "n8n-nodes-base.gmail",
"position": [
-1504,
-400
],
"webhookId": "55c11b0e-7461-43de-b9d3-a3904f3dd525",
"parameters": {
"simple": false,
"filters": {
"sender": "exemplo.email@gmail.com",
"receivedAfter": "2025-09-30T00:00:00",
"receivedBefore": "2025-09-22T00:00:00"
},
"options": {},
"operation": "getAll",
"returnAll": true
},
"credentials": {
"gmailOAuth2": {
"id": "ngFQG1C0p6o1ipTG1",
"name": "Gmail account 2"
}
},
"typeVersion": 2.1
},
{
"id": "2c6c6140-160d-4198-a0cc-3fa17530859e",
"name": "メール本文内要素検索",
"type": "n8n-nodes-base.html",
"position": [
-1280,
-400
],
"parameters": {
"options": {},
"operation": "extractHtmlContent",
"dataPropertyName": "html",
"extractionValues": {
"values": [
{
"key": "dados",
"attribute": "href",
"cssSelector": "=a[style*=\"color: #ffffff\"]",
"returnValue": "attribute"
}
]
}
},
"typeVersion": 1.2
},
{
"id": "7e6693f3-0607-49a3-9725-d844a8b45319",
"name": "リンクを開く",
"type": "n8n-nodes-base.httpRequest",
"onError": "continueErrorOutput",
"position": [
-1072,
-400
],
"parameters": {
"url": "={{ $json.dados }}",
"options": {}
},
"retryOnFail": false,
"typeVersion": 4.2,
"alwaysOutputData": false
},
{
"id": "4a04204c-e8dc-4865-963a-000378aa1024",
"name": "データ取得",
"type": "n8n-nodes-base.html",
"position": [
-832,
-416
],
"parameters": {
"options": {},
"operation": "extractHtmlContent",
"extractionValues": {
"values": [
{
"key": "dtnasc",
"cssSelector": "#lblMemberDateOfBirth"
},
{
"key": "id",
"cssSelector": "#txtCase"
},
{
"key": "data_solicitacao",
"cssSelector": "#lblCaseOpenOn"
},
{
"key": "Local_pt01",
"cssSelector": "#lblMemberFullAddress"
},
{
"key": "Local_pt02",
"cssSelector": "#lblLocationHotelName"
},
{
"key": "Nome",
"cssSelector": "#lblMemberFirstName"
},
{
"key": "sobrenome",
"cssSelector": "#lblMemberLastName"
},
{
"key": "Queixa",
"cssSelector": "#lblCaseReportedIssue"
},
{
"key": "Link",
"cssSelector": "=",
"returnValue": "value"
}
]
}
},
"typeVersion": 1.2
},
{
"id": "a3d87c4d-1c96-461c-bc45-42e4a3c7469c",
"name": "情報処理",
"type": "n8n-nodes-base.code",
"position": [
-608,
-416
],
"parameters": {
"jsCode": "// Função para converter string \"DD/MM/YYYY HH:MM\" para objeto Date\nfunction parseDateOnly(dateTimeStr) {\n if (!dateTimeStr) return null;\n const parts = dateTimeStr.split(' ')[0].split('/'); // pega apenas DD/MM/YYYY\n if (parts.length !== 3) return null;\n const day = parseInt(parts[0], 10);\n const month = parseInt(parts[1], 10) - 1; // meses em JS vão de 0 a 11\n const year = parseInt(parts[2], 10);\n return new Date(year, month, day);\n}\n\n// Função para extrair apenas o número do ID, removendo prefixos como \"Caso ID :\" ou \"Case ID :\"\nfunction extractCaseId(idStr) {\n if (!idStr) return null;\n return idStr.replace(/(Caso|Case)\\s*ID\\s*:\\s*/i, '').trim();\n}\n\n// Recupera todos os e-mails e links correspondentes\nconst emailItems = $('Search Emails').all();\nconst linkItems = $('search for an element in the email body').all();\n\n// Percorre todos os itens de entrada\nconst results = [];\nconst inputItems = $input.all();\n\nfor (let i = 0; i < inputItems.length; i++) {\n const item = inputItems[i];\n const birthDateStr = item.json.dtnasc;\n const requestDateTimeStr = item.json.data_solicitacao;\n const rawId = item.json.id;\n\n // Tratamento do ID\n const caseId = extractCaseId(rawId);\n\n // Captura o subject e o link correspondentes (mesmo índice)\n const emailSubject = emailItems[i]?.json?.headers?.subject || null;\n const emailLink = linkItems[i]?.json?.dados || null;\n\n // Determina o tipo de atendimento com base no subject\n let attendanceType = \"PRESENCIAL\";\n if (emailSubject && emailSubject.toLowerCase().includes(\"tele-medicine\")) {\n attendanceType = \"TELEMEDICINA\";\n }\n\n // Se faltar algum dado essencial, apenas devolve o item como está\n if (!birthDateStr || !requestDateTimeStr) {\n results.push({\n json: {\n ...item.json,\n caseId: caseId || null,\n emailSubject: emailSubject,\n attendanceType: attendanceType,\n link: emailLink\n }\n });\n continue;\n }\n\n const birthDate = parseDateOnly(birthDateStr);\n\n // Separar data e horário\n const [datePart, timePart] = requestDateTimeStr.split(' '); // \"DD/MM/YYYY\" e \"HH:MM\"\n const requestDate = parseDateOnly(datePart);\n\n if (!birthDate || !requestDate) {\n results.push({\n json: {\n ...item.json,\n caseId: caseId || null,\n emailSubject: emailSubject,\n attendanceType: attendanceType,\n link: emailLink\n }\n });\n continue;\n }\n\n // Calcula a idade\n let age = requestDate.getFullYear() - birthDate.getFullYear();\n const m = requestDate.getMonth() - birthDate.getMonth();\n if (m < 0 || (m === 0 && requestDate.getDate() < birthDate.getDate())) {\n age--;\n }\n\n // Retorna o item completo com todos os campos tratados\n results.push({\n json: {\n ...item.json,\n age: age,\n requestDate: datePart, // apenas a data\n requestTime: timePart, // apenas o horário\n caseId: caseId, // número do caso limpo\n emailSubject: emailSubject, // texto do subject do e-mail\n attendanceType: attendanceType, // \"TELEMEDICINA\" ou \"PRESENCIAL\"\n link: emailLink // link correspondente ao e-mail\n }\n });\n}\n\nreturn results;\n"
},
"typeVersion": 2
},
{
"id": "ac95be81-23fa-4833-9bbf-46a68d172a2f",
"name": "変数設定",
"type": "n8n-nodes-base.set",
"position": [
-384,
-416
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "bcf5bbaa-2930-4c59-93c3-add1b31fdb7c",
"name": "id",
"type": "string",
"value": "={{ $json.caseId }}"
},
{
"id": "c46a4f49-c77f-4239-83f2-1a1334bf31ae",
"name": "Nome_Paciente",
"type": "string",
"value": "={{ $json.Nome }} {{ $json.sobrenome }}"
},
{
"id": "a2b523a0-6d65-442f-a23a-5e2ec3e8f17f",
"name": "Dt_solicitacao",
"type": "string",
"value": "={{ $json.requestDate }}"
},
{
"id": "7b421b6a-99fe-479a-ac7d-c580c02f6ee0",
"name": "Queixa",
"type": "string",
"value": "={{ $json.Queixa }}"
},
{
"id": "11941808-a53b-4d12-aaef-910120a5b512",
"name": "Idade",
"type": "string",
"value": "={{ $json.age }}"
},
{
"id": "9a0ff300-33ec-4dc6-831f-e21ad8148b84",
"name": "Local",
"type": "string",
"value": "={{ $json.Local_pt01 }} {{ $json.Local_pt02 }}"
},
{
"id": "0133b215-4db9-47ea-a2b8-ef80a4f052fa",
"name": "horario",
"type": "string",
"value": "={{ $json.requestTime }}"
},
{
"id": "a42de334-56c3-4180-bc7c-d926ebd4c2b2",
"name": "Link",
"type": "string",
"value": "={{ $json.link }}"
},
{
"id": "85b87a31-662f-4ef4-9b73-9211b0bd9511",
"name": "Tipo atendimento",
"type": "string",
"value": "={{ $json.attendanceType }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "907f9531-8fdd-4bce-9a8a-b03e7edsdsdsd202180",
"name": "スプレッドシートにデータ保存",
"type": "n8n-nodes-base.googleSheets",
"position": [
-144,
-416
],
"parameters": {
"columns": {
"value": {
"DATA": "={{ $json.Dt_solicitacao }}",
"LINK": "={{ $json.Link }}",
"NOME": "={{ $json.Nome_Paciente }}",
" CASO": "={{ $json.id }}",
"IDADE": "={{ $json.Idade }}",
"LOCAL": "={{ $json.Local }}",
"QUEIXA": "={{ $json.Queixa }}",
"HORÁRIO": "={{ $json.horario }}",
"TIPO CONSULTA ": "={{ $json['Tipo atendimento'] }}"
},
"schema": [
{
"id": "HORÁRIO",
"type": "string",
"display": true,
"required": false,
"displayName": "HORÁRIO",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "DATA",
"type": "string",
"display": true,
"required": false,
"displayName": "DATA",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "EMPRESA",
"type": "string",
"display": true,
"required": false,
"displayName": "EMPRESA",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "TIPO CONSULTA ",
"type": "string",
"display": true,
"required": false,
"displayName": "TIPO CONSULTA ",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "LOCAL",
"type": "string",
"display": true,
"required": false,
"displayName": "LOCAL",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "NOME",
"type": "string",
"display": true,
"required": false,
"displayName": "NOME",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": " CASO",
"type": "string",
"display": true,
"required": false,
"displayName": " CASO",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "IDADE",
"type": "string",
"display": true,
"required": false,
"displayName": "IDADE",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "QUEIXA",
"type": "string",
"display": true,
"required": false,
"displayName": "QUEIXA",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "LINK",
"type": "string",
"display": true,
"required": false,
"displayName": "LINK",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "DIAGNOSTICO",
"type": "string",
"display": true,
"required": false,
"displayName": "DIAGNOSTICO",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "MEDICAÇÃO PRESCRITA",
"type": "string",
"display": true,
"required": false,
"displayName": "MEDICAÇÃO PRESCRITA",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "INJETAVEIS /PROCEDIMENTOS",
"type": "string",
"display": true,
"required": false,
"displayName": "INJETAVEIS /PROCEDIMENTOS",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "append",
"sheetName": {
"__rl": true,
"mode": "list",
"value": 311390915,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1bbcFz1111wO77RBr0t8hYaAEuzEsr24MJrFWuIPzoC-XMjx8/edit#gid=311390915",
"cachedResultName": "Outubro-2025"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1bbcFzO77RBr0t8hYaAEuzEsr24MJrFWuIPzoC-XMjx8",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1bbcFz111O77RBr0t8hYaAEuzEsr24MJrFWuIPzoC-XMjx8/edit?usp=drivesdk",
"cachedResultName": "NOREPLY"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "vwTaWWwUsdsdAfxbulmlj",
"name": "Google Sheets account"
}
},
"typeVersion": 4.7
},
{
"id": "9fedd068-0a9b-44a1-bde1-de312dfc6ced",
"name": "付箋",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1568,
-496
],
"parameters": {
"width": 208,
"height": 272,
"content": "**earch for emails** received from a sender within a specific time period."
},
"typeVersion": 1
},
{
"id": "584ddb97-097b-452c-a632-a534537965d0",
"name": "付箋1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1344,
-496
],
"parameters": {
"color": 4,
"width": 208,
"height": 272,
"content": "**Search for a specific css element** in the email code"
},
"typeVersion": 1
},
{
"id": "f1d3e50c-a187-421f-95a1-009f1f5c8f49",
"name": "付箋2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1120,
-496
],
"parameters": {
"color": 3,
"width": 208,
"height": 272,
"content": "**access the link** found in the HTML body of the email"
},
"typeVersion": 1
},
{
"id": "c434b579-5fb5-4813-9944-7af5f54101e6",
"name": "付箋3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-896,
-496
],
"parameters": {
"color": 4,
"width": 208,
"height": 272,
"content": "**Search for a specific css element** in the email code"
},
"typeVersion": 1
},
{
"id": "69282cbc-b64e-4923-b67d-f279cca4e509",
"name": "付箋4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-672,
-496
],
"parameters": {
"color": 5,
"width": 208,
"height": 272,
"content": "js code to process the extracted data, **customize as you wish**"
},
"typeVersion": 1
},
{
"id": "df2ead67-1e19-4cec-a79c-47259d756545",
"name": "付箋5",
"type": "n8n-nodes-base.stickyNote",
"position": [
-448,
-496
],
"parameters": {
"color": 5,
"width": 208,
"height": 272,
"content": "set the desired variables to save"
},
"typeVersion": 1
},
{
"id": "2d494ae1-6ab6-473e-8252-b3837a7ea469",
"name": "付箋6",
"type": "n8n-nodes-base.stickyNote",
"position": [
-208,
-496
],
"parameters": {
"width": 208,
"height": 272,
"content": "save the information to the desired Google spreadsheet."
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "ac8b921c-39c6-45d0-bb37-cba2366b53bf",
"connections": {
"4a04204c-e8dc-4865-963a-000378aa1024": {
"main": [
[
{
"node": "a3d87c4d-1c96-461c-bc45-42e4a3c7469c",
"type": "main",
"index": 0
}
]
]
},
"8473c056-35d1-4e47-96dd-e0cb30e14ad1": {
"main": [
[
{
"node": "2c6c6140-160d-4198-a0cc-3fa17530859e",
"type": "main",
"index": 0
}
]
]
},
"7e6693f3-0607-49a3-9725-d844a8b45319": {
"main": [
[
{
"node": "4a04204c-e8dc-4865-963a-000378aa1024",
"type": "main",
"index": 0
}
]
]
},
"ac95be81-23fa-4833-9bbf-46a68d172a2f": {
"main": [
[
{
"node": "907f9531-8fdd-4bce-9a8a-b03e7edsdsdsd202180",
"type": "main",
"index": 0
}
]
]
},
"a3d87c4d-1c96-461c-bc45-42e4a3c7469c": {
"main": [
[
{
"node": "ac95be81-23fa-4833-9bbf-46a68d172a2f",
"type": "main",
"index": 0
}
]
]
},
"996ac1ec-c471-4734-a82c-c44c16ce74ad": {
"main": [
[
{
"node": "8473c056-35d1-4e47-96dd-e0cb30e14ad1",
"type": "main",
"index": 0
}
]
]
},
"2c6c6140-160d-4198-a0cc-3fa17530859e": {
"main": [
[
{
"node": "7e6693f3-0607-49a3-9725-d844a8b45319",
"type": "main",
"index": 0
}
]
]
}
}
}よくある質問
このワークフローの使い方は?
上記のJSON設定コードをコピーし、n8nインスタンスで新しいワークフローを作成して「JSONからインポート」を選択、設定を貼り付けて認証情報を必要に応じて変更してください。
このワークフローはどんな場面に適していますか?
中級 - 文書抽出
有料ですか?
このワークフローは完全無料です。ただし、ワークフローで使用するサードパーティサービス(OpenAI APIなど)は別途料金が発生する場合があります。
関連ワークフロー
AI-Deepseek-R1t を用いた会議交通費精算申請と旅費承認
Deepseek AI、Gmail、Google Sheetsを使った会議出張承認の自動化
If
Set
Code
+
If
Set
Code
24 ノードCheng Siong Chin
文書抽出
PDFのテンプレートを抽出
Google Sheets追跡用Llama AIモデル
Set
Code
Html
+
Set
Code
Html
24 ノードCristian Baño Belchí
文書抽出
n8nノードの探索(可視化リファレンスライブラリ内)
n8nノードを可視化リファレンスライブラリで探索
If
Ftp
Set
+
If
Ftp
Set
113 ノードI versus AI
その他
私の冷蔵郵送メールジェネレーター
Anthropic、GPT-4、そしてGoogleシートを使ってパーソナライズされたアイスのメールを生成する
If
Set
Code
+
If
Set
Code
24 ノードBhuvanesh R
リードナーチャリング
API速率制限と認証に関するFAQテスト
GPT-4o-mini、Googleスプレッドシート、Slackアラートを使用したAPIよくある質問品質テストの自動化
If
Set
Code
+
If
Set
Code
19 ノードRahul Joshi
文書抽出
ゾルタリフォルシュング V2
Googleシートと関税APIによるHS項目コードクエリーとエンチッチメントの自動化
Set
Gmail
Aggregate
+
Set
Gmail
Aggregate
14 ノードThomas
文書抽出