【问题标题】:How to get Page Id from Confluence URL, or requests.get in Python? Want to set it as an object如何从 Confluence URL 或 Python 中的 requests.get 获取页面 ID?想将其设置为对象
【发布时间】:2019-09-10 17:48:09
【问题描述】:

在 Python 中,想要从 Confluence URL/标题页面 获取 页面 ID 并将其用于在代码中进一步发布到该页面。当我知道页面 ID 时,该过程已经开始工作,但需要每晚使用 Lambda 销毁和创建页面。

import requests

checkPageExistsData = requests.get(url, verify=False, headers=headers, auth=auth)
requestJson = checkPageExistsData.json()
pageId = ''

希望能打印或者返回pageId,基本上是想得到pageId

【问题讨论】:

    标签: python-3.x confluence-rest-api


    【解决方案1】:

    根据documentation

    http://example.com/confluence/rest/api/content?spaceKey=TST&title=Cheese

    然后您可以从响应 JSON 中获取 id

    【讨论】:

      【解决方案2】:

      能够从中得到我需要的东西:

      import requests
      import urllib3
      
      urllib3.disable_warnings()
      
      url ="https://xxxxx.com"
      headers={'Content-Type':'application/json'}
       auth=('xxxxxxxx', 'xxxxxxxxxxxx')
      
      
      def get_pageId():
          r = requests.get(url, verify=False, headers=headers, auth=auth)
          data = r.json()
          for results in data["results"]:
              id = (results["id"])
          return id
      
      pageID = get_pageId()
      print(pageID)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-22
        • 2013-05-28
        • 1970-01-01
        • 2013-06-22
        • 2015-11-04
        相关资源
        最近更新 更多