New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

resion

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Malware was recently detected in this package.

Affected versions:

22.0.1

resion

Minimal tree-based HTML parsing with basic selectors.

pipPyPI
Version
22.0.1
Weekly downloads
86
Maintainers
1
Weekly downloads
 
Created

resion

Minimal tree-based HTML parser built on the stdlib html.parser: an editable Node tree, basic selectors (tag, #id, .class), readable-text extraction and minification.

Install

pip install resion

Usage

import resion as rs

doc = rs.parse('<h1 id="t">Title</h1><p class="lead">Hi</p>')

doc.find('#t').text_content()        # 'Title'
doc.find_all('p')                    # [Node p]
doc.find('.lead').get_attr('class')  # 'lead'
rs.extract_text(doc)                 # readable text, boilerplate removed
rs.minify('<div> a </div><!-- x -->')

The tree is editable:

from resion import Node

doc.find('p').replace_with(Node('span'))
node = doc.find('#t')
node.set_attr('id', 'new').unwrap()
doc.to_html()

Settings are a Config or plain dict merged over defaults; a default.config next to the package is auto-loaded at import (falling back to built-in defaults when absent):

from resion import Config, Engine, get_config, load_config

engine = Engine({'strict_mode': True})
engine = Engine(load_config('my.config'))
get_config().get('strict_mode', False)

Bytes input is decoded via BOM sniffing and <meta charset> detection; oversized input and malformed HTML are rejected in strict mode with PafexError.

FAQs

Related posts