Ubuntu 16.04.4 LTS AEM 6.4

  • Use Python script to get the Reference of a page in AEM
    • Use your own AEM admin password HTTPBasicAuth('admin', 'password')
    • XPath to get all incomingLinks
    • Install lxml (please refer to Use Python to read HTML element by XPath)
      test.py
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      from lxml import html
      import requests

      # print (requestURL)
      page = requests.get("http://localhost:4502/mnt/overlay/wcm/core/content/sites/jcr:content/rails/references/items/references.provider.html?item=/content/mysite/intl/en/test", auth=requests.auth.HTTPBasicAuth('admin', 'password'))
      # print (page.content)
      content = html.fromstring(page.content)
      links = content.xpath('//section[@data-type="incomingLinks")]/@data-path')
      # Remove duplicate links
      links = list(set(links))

      for link in links:
      print (link)

  • Run the script
    1
    python3 test.py
2021-08-11