Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.HTML for Python via .NET is an API for creating, loading, editing, saving, extracting data from, and converting HTML and related web documents. Use HTMLDocument for HTML DOM operations and Converter for supported document conversions.
This FAQ gives concise answers to common Aspose.HTML for Python via .NET questions. Follow the links for complete examples, save options, format-specific guidance, and troubleshooting details.
Q: What is Aspose.HTML for Python via .NET?
A: Aspose.HTML for Python via .NET is a Python library for parsing and manipulating HTML documents through a Document Object Model (DOM). It also provides APIs for CSS processing, JavaScript, data extraction, document saving, and conversion to PDF, DOCX, XPS, and raster image formats. See the
Features List for an overview.
Q: How do I install Aspose.HTML for Python via .NET?
A: Install the aspose-html-net package from PyPI:
1pip install aspose-html-netThe package name is aspose-html-net, while Python classes are imported from the aspose.html namespace. See
Installation for upgrade, verification, and troubleshooting commands.
Q: Why does Python report ModuleNotFoundError for aspose?
A: The package may have been installed for a different Python interpreter or virtual environment. Activate the intended environment, verify the installation with pip show aspose-html-net, and run the application with the corresponding interpreter. The
Installation Troubleshooting section covers the common causes.
Q: Can I use Aspose.HTML for Python via .NET for free?
A: Aspose.HTML for Python via .NET is a commercial library, but it can be installed and evaluated without a license. Evaluation mode applies output limitations such as watermarks and processing limits. A free temporary license can be used to test the library without those evaluation restrictions. See
Licensing.
Q: Which Python versions and operating systems are supported?
A: Compatibility depends on the available package for the Python version, operating system, and processor architecture. Check
System Requirements before selecting a development or deployment environment.
Q: Where can I find complete Python examples?
A: Documentation pages contain focused snippets, while the
Aspose.HTML for Python via .NET GitHub repository provides complete examples and supporting files.
Q: How do I convert HTML to PDF in Python?
A: Use
Converter.convert_html() with
PdfSaveOptions:
PdfSaveOptions for PDF output.Converter.convert_html() with the source, options, and destination path.1import aspose.html.converters as conv
2import aspose.html.saving as sav
3
4conv.Converter.convert_html(
5 "document.html",
6 sav.PdfSaveOptions(),
7 "output.pdf"
8)See Convert HTML to PDF in Python for file, string, URL, and custom-options workflows.
Q: What input and output formats are supported?
A: Aspose.HTML processes HTML, XHTML, MHTML, SVG, Markdown, and EPUB as supported source formats. Depending on the source and API, output can include HTML-related formats, PDF, XPS, DOCX, PNG, JPEG, TIFF, BMP, GIF, and WebP. PDF, XPS, and DOCX are output formats rather than source-document formats. See
Supported File Formats for the input and output matrix.
Q: Can Aspose.HTML convert an existing PDF or DOCX file to HTML?
A: No. PDF and DOCX are supported output formats in Aspose.HTML for Python via .NET, not input formats for HTML processing. Choose an API designed to load the source document format when a workflow starts from PDF or DOCX.
Q: Can I convert a webpage URL to PDF in Python?
A: Yes. Pass an aspose.html.Url object to a supported Converter.convert_html() overload, or load the webpage into an HTMLDocument before conversion. The application must be able to access the page and its linked stylesheets, images, fonts, scripts, and other resources. See
Convert a Webpage URL to PDF.
Q: Can I convert an HTML string without creating a temporary file?
A: Yes. Pass the HTML string, a base URI, save options, and an output path to a supported Converter.convert_html() overload. The base URI is important when the markup contains relative URLs for CSS, images, fonts, scripts, or links.
Q: What is a base URI and why is it needed?
A: A base URI supplies the location against which relative URLs are resolved. For example, an image reference such as images/logo.png cannot be loaded reliably from an isolated HTML string unless the converter knows the base folder or URL. File- and URL-based documents normally obtain this location from their source.
Q: Can I convert HTML to PNG, JPG, or other images?
A: Yes. Use Converter.convert_html() with ImageSaveOptions and select the required ImageFormat. See
Convert HTML to Image in Python for PNG, JPEG, GIF, BMP, and TIFF guidance and links to format-specific examples.
Q: Can I load EPUB, MHTML, or SVG with HTMLDocument?
A: HTMLDocument is intended for HTML and XHTML. Use SVGDocument when the SVG DOM must be inspected or edited. Use the source-specific conversion methods and guides for
EPUB,
MHTML,
SVG, and
Markdown.
Q: How do I customize PDF, image, DOCX, or XPS output?
A: Create the save-options class for the target format and configure only the settings required by the result. Depending on the format, options can control page size, margins, image resolution, background color, metadata, font embedding, encryption, or other output-specific behavior. See
Fine-Tuning Converters and the guide for the selected format.
Q: Why are CSS, images, scripts, or fonts missing from converted output?
A: Relative resource URLs must resolve against the document location or a valid base URI. Confirm that local paths are correct, remote resources are accessible, sandbox settings do not block them, and required fonts are available in the rendering environment. A webpage can also produce incomplete output when required content is generated asynchronously or a remote request fails.
Q: Does Aspose.HTML convert Python source code to HTML?
A: No. Python is the programming language used to call the Aspose.HTML API. The library converts supported document and web formats; it does not translate Python source code into an HTML representation.
Q: Can I create and edit HTML documents in Python?
A: Yes. Create an empty HTMLDocument or load HTML from a file, URL, string, or stream. DOM APIs can then create or remove nodes, update attributes and text, and modify inline or internal CSS. Start with
Create and Load HTML Documents and
Edit HTML Documents.
Q: How do I save HTML with images, CSS, fonts, and scripts?
A: Call HTMLDocument.save() and use HTMLSaveOptions with resource-handling settings. Resources can be saved as separate files, embedded in the HTML, ignored, or discarded according to the selected configuration. See
Save HTML with Resources.
Q: Does Aspose.HTML support CSS selectors in Python?
A: Yes. Use query_selector() to return the first matching element and query_selector_all() to return all matches. See
Use CSS Selectors in Python for element, class, ID, attribute, and combined-selector examples.
Q: Does Aspose.HTML support XPath in Python?
A: Yes. Use the document’s
evaluate() method to execute XPath expressions. See
Use XPath in HTML with Python for node and attribute selection examples.
Q: Can I extract text, tables, links, images, or SVG from HTML?
A: Yes. Load the document, select the relevant DOM elements, read their text or attributes, resolve relative URLs where necessary, and save or process the results. The
Data Extraction section provides separate guides for text, tables, links, images, and SVG.
Q: Is Aspose.HTML a complete web-scraping framework?
A: Aspose.HTML can load webpages, build a DOM, run selectors or XPath queries, and extract content and resources. It does not replace all crawler infrastructure, such as site-wide scheduling, retry queues, login automation, rate limiting, or storage pipelines. Applications should implement those concerns separately when required.
Q: Can I disable JavaScript or image loading?
A: Yes. Create a Configuration, add Sandbox.SCRIPTS, Sandbox.IMAGES, or other required flags to configuration.security, and pass the configuration when loading the document. Apply the restrictions before creating HTMLDocument. See
Sandbox Untrusted HTML in Python.
Q: Does sandboxing make untrusted HTML completely safe?
A: No. Aspose.HTML sandbox flags restrict selected document capabilities, but they are not an operating-system security boundary. Continue to use appropriate process isolation, file permissions, network policies, input validation, and other application security controls.
Q: Does max_handling_depth improve conversion performance?
A: Not as a general performance setting.
ResourceHandlingOptions.max_handling_depth controls how many levels of linked HTML pages may be processed while saving. It does not limit DOM nesting and does not directly optimize HTML-to-PDF or HTML-to-image conversion. See
Control Resource URLs and Linked Pages.
Q: Why do characters appear as boxes or use the wrong font?
A: First check the source character encoding. If the text is parsed correctly but renders as boxes or substituted glyphs, the required font may be missing or may not contain those characters. Install or provide appropriate fonts and keep the rendering environment consistent.
Q: Why can rendering look different on another machine?
A: Output can change when environments use different fonts, package versions, locale settings, input resources, or network access. For reproducible rendering, keep those dependencies and settings consistent across development, test, and production systems.
Q: Why does loading a webpage take a long time?
A: HTMLDocument constructors that load external content operate synchronously and can wait for linked resources. A complex or unreachable resource can therefore delay the workflow. Reduce unnecessary resource loading with an appropriate configuration, check network availability, or use the document navigation APIs when asynchronous loading is required.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.