Working with HTML Documents in Python – Create, Edit, and Save HTML

The Working with HTML Documents section explains how to create, load, edit, and save documents with Aspose.HTML for Python via .NET. These articles focus on document-level operations with the HTML Document Object Model (DOM), CSS, and linked resources.

Use HTMLDocument to create or load HTML, access and modify the DOM, and save the result with save(). Use the appropriate conversion API instead when the required output is PDF, DOCX, XPS, or a raster image.

Choose a Document Workflow

Typical Python HTML Document Workflow

Most document-processing tasks follow the same sequence:

  1. Identify whether the HTML source is a local file, URL, string, stream, or a document created from scratch.
  2. Create or load an HTMLDocument and access its DOM tree.
  3. Read or modify elements, attributes, text, CSS, and linked resources.
  4. Save the document with HTMLDocument.save() and configure save options when linked resources require special handling.
  5. Use a converter instead of save() when the required result is PDF, DOCX, XPS, or a raster image.

Saving preserves or serializes HTML and its resources. Conversion renders or transforms the source into another output format. Edit the DOM or CSS before either operation when the output must include those changes.

Main APIs Covered in This Section

Related Sections

Try Online HTML Applications

Use the free HTML Web Applications for quick conversion, merging, encoding, and web-page analysis without installing software. Use Aspose.HTML for Python via .NET when these workflows must run programmatically in an application or service.

HTML Web Applications