You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is now supported through the modern Site Pages API. Your snippet only loads the web's own properties — to get a page's HTML you read the page's canvas content (CanvasContent1):
fromoffice365.sharepoint.client_contextimportClientContextctx=ClientContext("https://company.sharepoint.com/sites/<site>").with_credentials(
UserCredential("[email protected]", "password")
)
# a single page, by file namepage=ctx.site_pages.pages.get_by_name("Home.aspx").execute_query()
html=page.canvas_contentor""# raw HTML stored in CanvasContent1# or every pageforpageinctx.site_pages.pages.get().execute_query():
print(page.file_name, len(page.canvas_contentor""), "chars")
canvas_content is the authored HTML of the page. Embedded files, images and videos are referenced, not inlined.
A full runnable example that exports every modern page to a .html file is in the repo: examples/sharepoint/pages/export_html.py (see also get_content.py, paged.py, and the guide at examples/sharepoint/pages/README.md).
For classic (wiki / web part) pages, read the page file directly, e.g.:
Activity
henrikruneskog commentedon Jul 7, 2023
I also have this question. @WG- did you solve it?
office365-maintainer commentedon Oct 3, 2026
This is now supported through the modern Site Pages API. Your snippet only loads the web's own properties — to get a page's HTML you read the page's canvas content (
CanvasContent1):canvas_contentis the authored HTML of the page. Embedded files, images and videos are referenced, not inlined.A full runnable example that exports every modern page to a
.htmlfile is in the repo:examples/sharepoint/pages/export_html.py(see alsoget_content.py,paged.py, and the guide atexamples/sharepoint/pages/README.md).For classic (wiki / web part) pages, read the page file directly, e.g.:
Closing as answered — please reopen if this doesn't cover your case.