Get the contents of table in a confluence page using REST API
Asked by Aswini Vayyala:

How can I get the contents of a table in a confluence page using REST API?

I was able to get the content of the page. But I just want the contents of the table as a list. Any pointers will be appreciated.


Answers:
author: Alex Yasurek
body: Yea there is no direct way to get just the table. You have to get all the content and then parse it yourself to get only the table. I am not sure what programming language you are using for this but for python one good library for this is called BeautifulSoup (<https://www.crummy.com/software/BeautifulSoup/bs4/doc/>).

There are similar libraries like this for other languages so I would look for one in your language and use it to parse the content.

comments: author: Brahm Bothma
body: This relates to the following Confluence Server Page:

Confluence REST API examples {#toc-hId-1820206815}
--------------------------------------------------

<https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/>

This page contains examples of using the Confluence Content REST API using `curl`. The responses are piped into `python -mjson.tool` ([JSON encoder / decoder](https://docs.python.org/2.6/library/json.html)) to make them easier to read.


author: George Ivanov
body: Hi All,

you can use the following macro: <https://v-and-b.atlassian.net/wiki/spaces/PD/pages/1127186433/Table+Scraper+from+URL+Macro>

Here are step-by-step instructions: <https://v-and-b.atlassian.net/wiki/spaces/PD/blog/2020/05/26/1142554679/How+to+Display+a+HTML+Table+from+a+URL+as+a+Confluence+Table>

comments: author: ravikanth mogulla
body: The question was to get contents from a confluence table. This macro is about scraping a webpage URL, get contents and display in Confluence table.

Hows it related?


author: Mohan
body: Hi,

can any of you provide details about how to scrape table contents from table in confluence page by using rest api \& then python script?

comments: author: Nipun Goel
body: you found anything , stucked in same problem.


author: Pierre Ibrahim
body: [@Mohan](/t5/user/viewprofilepage/user-id/2272377) , [@Nipun Goel](/t5/user/viewprofilepage/user-id/3456873),

For parsing tables I used the following [Stack Overflow answer](https://stackoverflow.com/questions/6325216/parse-html-table-to-python-list), specifically the response by [schmijos.](https://stackoverflow.com/users/430418/schmijos)

Use this in tandem with a requests.get for the URL you want from confluence, and make sure to add the following at the end of the URL

```
?expand=body.view
```


author: George Ivanov
body: Hi, you can use the following macro: <https://v-and-b.atlassian.net/wiki/spaces/PD/pages/1127186433/Table+Scraper+from+URL+Macro>


author: Wenchang Zhou
body: hey [@George Ivanov](/t5/user/viewprofilepage/user-id/1891392)  

I have a page that has similar url as yours <https://v-and-b.atlassian.net/wiki/spaces/PD/pages/1127186433/Table+Scraper+from+URL+Macro>, do you know what would be the url, if I want to extract content from that page? I often see people have urls that contain "rest/api/content" which I don't have. Thanks


author: Rupa Jain
body: How did you get the content of the page using REST API? Did it contain table values?

comments: author: Steven F Behnke
body: The REST API (which you can find on google) includes all page content in XML format. Of course it includes a normal html table, yes.


author: nishanth.shenoy
body: ```
https://<domain>/rest/api/content/12345?expand=body.storage
```

This format can be used to get the contents of the confluence page.


author: Steven F Behnke
body: Your best bet is to grab the storage format and parse the returned XML for your table.


Tags: rest-api

table