Aspose.HTML FOSS for Python은 Python 애플리케이션에서 HTML 문서를 다루기 위한 무료 오픈소스 라이브러리입니다. 단일 git clone https://github.com/aspose-html-foss/Aspose.HTML-FOSS-for-Python.git 명령으로 설치하고 마크업을 문서 객체 모델로 파싱하고, 요소 트리를 구축·수정하고, CSS 스타일시트를 첨부하고, 계산된 스타일을 해결하며, URL 및 문자 인코딩을 다루기 시작하세요 — 모두 브라우저 의존성 없이 순수 Python로 구현됩니다.
이 라이브러리는 HTMLDocument, Document, Element, CSSStyleSheet를 중심으로 구성된 표준 지향 API를 제공합니다. HTMLDocument.parse() 로 마크업을 파싱하고, Document.create_element()와 append_child() 로 노드를 생성·연결하며, get_element_by_id() 로 요소를 찾고, CSSStyleSheet.replace_sync() 및 요소 수준의 style 선언을 통해 스타일을 적용하고, Element.get_computed_style() 로 결과를 읽어올 수 있습니다. 보다 낮은 수준의 빌딩 블록 — HTML Tokenizer, TreeBuilder, WHATWG 스타일 URL 및 URLSearchParams, 그리고 detect_encoding() 바이트 스트림 탐지기 — 는 직접 제어가 필요할 때 사용할 수 있습니다.
Aspose.HTML FOSS은 MIT 라이선스를 따르며 순수 Python로 구현되어 Python 3.10 이상이 필요합니다. Windows, Linux, macOS에서 동일하게 실행되며 — CI 러너, Docker 컨테이너, 서버리스 환경을 포함합니다. 엔터프라이즈 제품군에 대해서는 Aspose.HTML — Enterprise Product Family를 참조하십시오.
HTMLDocument.parse()를 사용하여 전체 페이지를 파싱하거나 HTMLDocument.parse_fragment()를 사용하여 조각을 파싱합니다Document.create_element()와 append_child()를 사용해 프로그래밍 방식으로 문서를 구축합니다Document.get_element_by_id()로 노드를 조회하고 Element.get_attribute()를 통해 마크업 속성을 읽습니다Element.set_attribute()로 속성을 설정하고 Node.text_content를 통해 텍스트를 할당합니다serialise() 함수를 사용해 서브트리를 마크업으로 직렬화합니다CSSStyleSheet.replace_sync() 로 스타일시트 텍스트를 파싱하고 Document.attach_style_sheet() 로 첨부합니다CSSStyleDeclaration.set_property() 를 사용하여 요소의 style 속성을 통해 인라인 선언을 설정합니다Element.get_computed_style() 로CSSStyleDeclaration.get_property_value() 로 해결된 값을 읽어옵니다Tokenizer.tokenize() 또는 Tokenizer.tokenize_fragment() 로 HTML 토크나이저를 직접 구동합니다TreeBuilder.run() 으로 표준 기반 트리 구성을 실행합니다parse_html() 함수를 사용하여 마크업을 직접 트리로 파싱합니다URL.parse()와 URL.can_parse()를 사용하여 URL을 구문 분석하고 검증합니다URLSearchParams를 사용하여 쿼리 문자열을 읽고 편집합니다 — append(), get(), has(), delete()detect_encoding()을 사용하여 바이트 스트림 인코딩(BOM 및 콘텐츠 스니핑)을 감지합니다get_canonical_name()을 사용하여 인코딩 레이블을 정규화된 이름으로 변환합니다문서를 생성하고 스타일시트를 첨부한 다음 계산된 스타일을 읽어보세요 — ID 선택자가 클래스 규칙보다 우선합니다:
from aspose_html.dom import Document
from aspose_html.cssom import CSSStyleSheet
doc = Document()
el = doc.create_element("div")
el.set_attribute("class", "foo")
el.set_attribute("id", "bar")
doc.append_child(el)
sheet = CSSStyleSheet()
sheet.replace_sync(".foo { color: red } #bar { color: blue }")
doc.attach_style_sheet(sheet)
style = el.get_computed_style()
print(style.get_property_value("color"))
인라인 선언은 작성자 스타일시트 규칙보다 높은 특이성을 가집니다:
from aspose_html.dom import Document
from aspose_html.cssom import CSSStyleSheet
doc = Document()
el = doc.create_element("div")
doc.append_child(el)
sheet = CSSStyleSheet()
sheet.replace_sync("div { color: red }")
doc.attach_style_sheet(sheet)
inline = el.style
inline.set_property("color", "blue")
print(el.get_computed_style().get_property_value("color"))
BOM을 포함한 원시 바이트 스트림의 인코딩을 감지하고, 디코딩된 텍스트를 반환합니다:
from aspose_html.encoding.detection import detect_encoding
result = detect_encoding(b"\xef\xbb\xbf<p>x</p>")
print(result.encoding)
print(result.confidence)
print(result.text)
MIT 라이선스 — 상업적 사용, 수정 및 재배포가 모두 허용됩니다; 유일한 요구 사항은 실질적인 사본에 저작권 고지를 유지하는 것입니다.
Python 3.10 이상. git clone https://github.com/aspose-html-foss/Aspose.HTML-FOSS-for-Python.git 로 설치하십시오 — 구현은 순수 Python이며 네이티브 종속성이 없습니다.
전체 페이지에는 HTMLDocument.parse()를 사용하고, 부분 마크업에는 HTMLDocument.parse_fragment()를 사용하십시오; Document는 프로그래밍 방식으로 트리를 구축하기 위한 팩토리입니다.
예 — 계산된 값은 선택자 특이성을 따르고, 인라인 선언은 작성자 규칙보다 우선하며, !important 작성자 규칙은 비-important 인라인 선언보다 우선하고, 상속은 부모에서 자식으로 흐릅니다.
아니요. 현재 릴리스는 파싱, DOM 조작, CSS 스타일 계산, 레이아웃 구조, URL 및 인코딩에 중점을 두며 — 형식 변환이나 이미지/PDF 렌더링은 포함되지 않습니다.
아니오. 파싱은 절대 스크립트를 실행하지 않습니다; 평가는 명시적이며 JSContext를 통해 옵트인하고, 모듈 로딩은 ModuleRegistry와 ModuleLoadPolicy에 의해 제어됩니다.