Edit page in Livemark
(2022-09-19 18:33)

Html Format

Frictionless supports parsing HTML format:

pip install frictionless[html]
pip install 'frictionless[html]' # for zsh shell

Reading Data

You can this file format using Package/Resource, for example:

from pprint import pprint
from frictionless import Resource

resource = Resource(path='table1.html', type='table')
pprint(resource.read_rows())
[{'id': 1, 'name': 'english'}, {'id': 2, 'name': '中国人'}]

Writing Data

The same is actual for writing:

from frictionless import Resource

source = Resource(data=[['id', 'name'], [1, 'english'], [2, 'german']])
target = source.write('table-output.html', type='table')
print(target)
print(target.to_view())
{'name': 'table-output',
 'type': 'table',
 'path': 'table-output.html',
 'scheme': 'file',
 'format': 'html',
 'mediatype': 'text/html'}
+----+-----------+
| id | name      |
+====+===========+
|  1 | 'english' |
+----+-----------+
|  2 | 'german'  |
+----+-----------+

Configuration

There is a dialect to configure HTML, for example:

from frictionless import Resource, formats

control=formats.HtmlControl(selector='#id')
resource = Resource(path='table1.html', type='table', control=control)
print(resource.read_rows())
[]

Reference

formats.HtmlControl (class)

formats.HtmlControl (class)

Html control representation

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, selector: str = table) -> None

Parameters

  • title (Optional[str])
  • description (Optional[str])
  • selector (str)

formats.htmlControl.selector (property)

NOTE: add docs

Signature

str

It's a beta version of Frictionless Framework (v5). Read Frictionless Framework (v4) docs for a version that is currently installed by default by pip.