Last active 1755442895

Скачивает html-контент указанной страницы и всех вложенных

confluence_get_article.sh Raw
1#!/bin/bash
2
3# 1. Указать реквизиты доступа к confluence
4USERNAME=""
5PASSWORD=""
6CONFLUENCE_URL=""
7OUTPUT_PATH="./confluence/"
8
9# 2. Вызвать: ./confluence_get_article.sh <page_id>
10
11##################################################################
12
13if [ $# -lt 1 ]; then
14 echo "Usage: $0 <article_id>"
15 exit 1
16fi
17
18command -v curl >/dev/null 2>&1 || { echo >&2 "Error: curl is required but not installed."; exit 1; }
19command -v jq >/dev/null 2>&1 || { echo >&2 "Error: jq is required but not installed."; exit 1; }
20
21DELAY=1
22ARTICLE_ID="$1"
23API_ENDPOINT="${CONFLUENCE_URL}/rest/api/content/${ARTICLE_ID}?expand=body.storage,children.page"
24
25echo
26echo "Downloading: $API_ENDPOINT"
27
28response=$(curl -s -u "$USERNAME:$PASSWORD" -H "Accept: application/json" "${API_ENDPOINT}")
29if [ $? -ne 0 ]; then
30 echo "Error: Failed to retrieve article"
31fi
32
33error_message=$(echo "$response" | jq -r '.message' 2>/dev/null)
34if [ -n "$error_message" ] && [ "$error_message" != "null" ]; then
35 echo "API Error: $error_message"
36else
37 title=$(echo "$response" | jq -r .title)
38 content=$(echo "$response" | jq -r .body.storage.value)
39 [ ! -d "$OUTPUT_PATH" ] && mkdir -p "$OUTPUT_PATH"
40 echo "<html><body>$content</body></html>" > "$OUTPUT_PATH/$title.html"
41 echo "Saved as: $OUTPUT_PATH/$title.html"
42
43 child_ids=$(echo "$response" | jq -r '.children.page.results[]?.id' 2>/dev/null)
44 for child_id in $child_ids; do
45 echo "Downloading child page ID: $child_id"
46 sleep $DELAY
47 ./confluence_get_article.sh "$child_id"
48 done
49fi
50