如何在合流中批量下载页面作为单个pdf?



我试图从我的汇流下载页面作为单独的pdf文件。我有超过50个子页面,我想下载每个页面作为单独的pdf。例如:

Parent of Parent   
Parent Page
Child Page 1
Child Page 2
Child page 3

我想将子页1、2和3作为单独的pdf下载。

是否有任何方法或脚本来做到这一点?也许python ?请帮帮我,伙计们

您可以通过使用atlassian-python-api==3.27.0来实现这一点。

获取页id指令

如果你只想从父端下载子元素:

from atlassian import Confluence
PARENT_PAGE_ID = 'parent page id'
# This creates connection object confluence with your credentials
confluence = Confluence(
url='https://confluence.xxxxx.com/',
username='your_username',
password='your_password'
)
# Get object contains pages information
children = confluence.get_child_pages(PARENT_PAGE_ID)
for i in children:
title = i['title']
id = i['id']
pdf_name = title + '.pdf'
# Get confluence page as byte-stream
content = confluence.get_page_as_pdf(id)
file_pdf = open(pdf_name, 'wb')
file_pdf.write(content)
file_pdf.close()

如果你想下载所有的子节点和它们的子节点,你必须使用递归:

def tree_downloader(confluence: Confluence, children: list) -> list:
list_id = []
for i in children:
if isinstance(i, str):
i_id = i
else:
i_id = i['id']
grandchildren = confluence.get_child_pages(i_id)
list_id.append(i_id)
if grandchildren:
list_id.extend(tree_downloader(confluence, grandchildren))
return list_id

编辑:这是你的函数的版本:

children = confluence.get_child_pages(PARENT_PAGE_ID)
children = tree_downloader(confluence, children)
for i in children:
p = confluence.get_page_by_id(i)
title = p['title']
id = p['id']
pdf_name = title+'.pdf'
content = confluence.get_page_as_pdf(id)
file_pdf = open(pdf_name, 'wb')
file_pdf.write(content)
file_pdf.close()

最新更新