【问题标题】:Connect to page with table Confluence with Python使用 Python 连接到带有表格的页面 Confluence
【发布时间】:2016-09-13 10:35:49
【问题描述】:

我在 Centos 上使用Confluence 启动了一个服务器,并创建了一个带有表格的页面。

现在我想连接到我的页面,然后在那里解析 html 并找到行和列,但我无法连接到页面。

我的页面位于:http://localhost:8090/display/TEST/Confluence

如何连接到我的页面并解析 HTML?

【问题讨论】:

    标签: python-2.7 confluence confluence-rest-api


    【解决方案1】:

    您可以使用 confluenca api 获取页面 ID

    from atlassian import Confluence
    space = '~MYSPACE'
    title_parent = 'PARENT_PAGE_ID'
    p_id = confluence.get_page_id(space, title_parent)
    print(p_id)
    
    title = 'New page'
    body = 'This is the body of a new page'
    status = confluence.create_page(space, title, body, parent_id=p_id, type='page', 
                                    representation='storage')
    print(status)
    

    【讨论】:

      【解决方案2】:

      查看 Atlassian 示例 here。要更新您的页面,您需要知道您的页面 ID。

      【讨论】:

        【解决方案3】:

        最好提出两个请求。第一个是返回页面 ID 的搜索,而后者将返回其内容。

        1. 搜索
            import requests
            url = confluence_host + '/rest/api/content/'
            res = requests.get(url=url + 'search',
                               params={'cql': 'space="TEST" AND title="Page Titile'})
            page_id = res.json()['results'][0]['id']
        
        1. 获取 HTML
            import requests
            url = confluence_host + '/rest/api/content/'
            page = requests.get(url=url + page_id,
                                params={'expand': 'body.storage'}).json()
            html = page['body']['storage']['value']
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-10-13
          • 1970-01-01
          • 1970-01-01
          • 2016-09-05
          • 2011-03-28
          • 1970-01-01
          • 1970-01-01
          • 2015-09-25
          相关资源
          最近更新 更多