fasthtmlparser-pure 0.1.1__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/LICENSE.md +1 -1
  2. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/PKG-INFO +3 -1
  3. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/README.md +2 -0
  4. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure/__init__.py +1 -1
  5. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure/_xpath.py +34 -2
  6. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure.egg-info/PKG-INFO +3 -1
  7. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/pyproject.toml +1 -1
  8. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure/_api.py +0 -0
  9. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure/_api.pyi +0 -0
  10. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure/_attrs.py +0 -0
  11. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure/_chars.py +0 -0
  12. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure/_css.py +0 -0
  13. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure/_decode.py +0 -0
  14. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure/_links.py +0 -0
  15. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure/_parser.py +0 -0
  16. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure/_query.py +0 -0
  17. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure/_tables.py +0 -0
  18. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure/_text.py +0 -0
  19. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure/py.typed +0 -0
  20. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure.egg-info/SOURCES.txt +0 -0
  21. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure.egg-info/dependency_links.txt +0 -0
  22. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/fasthtmlparser_pure.egg-info/top_level.txt +0 -0
  23. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/setup.cfg +0 -0
  24. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/tests/test_api.py +0 -0
  25. {fasthtmlparser_pure-0.1.1 → fasthtmlparser_pure-0.1.2}/tests/test_conformance.py +0 -0
@@ -53,7 +53,7 @@ more**, the Licensee must purchase a Commercial License.
53
53
  - A Licensee that stops being a Small Licensee (its Annual Revenue or Headcount reaches the
54
54
  threshold) while already using the Software must purchase the Commercial License within
55
55
  30 days.
56
- - To purchase: https://romanti3172.github.io/z3l.FastHtmlParser/#pricing, or contact **romanti3172@gmail.com** for an invoice.
56
+ - To purchase: https://fasthtmlparser.com/#pricing, or contact **romanti3172@gmail.com** for an invoice.
57
57
 
58
58
  The Commercial License grants the same rights as section 2, without the revenue and headcount
59
59
  limits.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fasthtmlparser-pure
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Fast HTML / XML parser for scraping with XPath 1.0 and CSS selectors, in pure Python. A port of z3l.FastHtmlParser.
5
5
  Author: z3l
6
6
  License-Expression: LicenseRef-z3l-FastHtmlParser
@@ -28,6 +28,8 @@ Dynamic: license-file
28
28
  [![CI](https://github.com/romanti3172/fasthtmlparser-pure/actions/workflows/ci.yml/badge.svg)](https://github.com/romanti3172/fasthtmlparser-pure/actions/workflows/ci.yml)
29
29
  [![PyPI](https://img.shields.io/pypi/v/fasthtmlparser-pure.svg)](https://pypi.org/project/fasthtmlparser-pure/)
30
30
 
31
+ **Website:** [fasthtmlparser.com](https://fasthtmlparser.com): try the parser on any page, documentation and every language.
32
+
31
33
  A fast HTML / XML parser for scraping, with **XPath 1.0** and **CSS selectors**, in **pure Python**: a port of
32
34
  [z3l.FastHtmlParser](https://github.com/romanti3172/z3l.FastHtmlParser) with no compiled code and no dependencies. It
33
35
  is built for extracting data, not for building a DOM: a page becomes a flat list of tags that hold only positions in
@@ -3,6 +3,8 @@
3
3
  [![CI](https://github.com/romanti3172/fasthtmlparser-pure/actions/workflows/ci.yml/badge.svg)](https://github.com/romanti3172/fasthtmlparser-pure/actions/workflows/ci.yml)
4
4
  [![PyPI](https://img.shields.io/pypi/v/fasthtmlparser-pure.svg)](https://pypi.org/project/fasthtmlparser-pure/)
5
5
 
6
+ **Website:** [fasthtmlparser.com](https://fasthtmlparser.com): try the parser on any page, documentation and every language.
7
+
6
8
  A fast HTML / XML parser for scraping, with **XPath 1.0** and **CSS selectors**, in **pure Python**: a port of
7
9
  [z3l.FastHtmlParser](https://github.com/romanti3172/z3l.FastHtmlParser) with no compiled code and no dependencies. It
8
10
  is built for extracting data, not for building a DOM: a page becomes a flat list of tags that hold only positions in
@@ -25,7 +25,7 @@ from ._api import (
25
25
  parse,
26
26
  )
27
27
 
28
- __version__ = "0.1.1"
28
+ __version__ = "0.1.2"
29
29
 
30
30
  __all__ = [
31
31
  "CssQuery",
@@ -43,6 +43,9 @@ E_ATTR_EXISTS = 9 # name: [@name]
43
43
  E_PATH = 10 # start (expr or None), absolute, steps; attr: a bare @name
44
44
  E_FILTER = 11 # primary, preds
45
45
  E_FUNCTION = 12 # fn, args
46
+ # fn, l (prefix), name, r (suffix), value (needle): contains/starts-with/ends-with(concat(l, @name, r), value),
47
+ # tested on the attribute in place (prefix and suffix may be empty)
48
+ E_ATTR_TEST = 13
46
49
 
47
50
  OP_EQ = 0
48
51
  OP_NEQ = 1
@@ -630,7 +633,24 @@ class _Compiler:
630
633
  if fn in ("count", "sum", "name", "local-name") and args and args[0].type != TYPE_NODE_SET:
631
634
  self.fail_at(f"{fn}() needs a node-set argument", t.p)
632
635
  pos = fn == "position" or fn == "last" or any(a.pos for a in args)
633
- return Expr(E_FUNCTION, info[2], pos, fn=fn, args=args)
636
+ return self.make_attribute_test(fn, args) or Expr(E_FUNCTION, info[2], pos, fn=fn, args=args)
637
+
638
+ def make_attribute_test(self, fn, args):
639
+ """contains(@a, 'x'), starts-with(...), ends-with(...), also with the attribute wrapped in literals
640
+ (contains(concat(' ', @class, ' '), ' x '), the usual class test), are evaluated on the attribute in place,
641
+ without a node-set for every element. None: a plain function call."""
642
+ if fn not in ("contains", "starts-with", "ends-with") or args[1].op != E_LITERAL:
643
+ return None
644
+ arg = args[0]
645
+ name = self.attribute_name(arg)
646
+ if name is not None:
647
+ return Expr(E_ATTR_TEST, TYPE_BOOLEAN, False, fn=fn, l="", name=name, r="", value=args[1].value)
648
+ if arg.op == E_FUNCTION and arg.fn == "concat" and len(arg.args) == 3 and arg.args[0].op == E_LITERAL and arg.args[2].op == E_LITERAL:
649
+ name = self.attribute_name(arg.args[1])
650
+ if name is not None:
651
+ return Expr(E_ATTR_TEST, TYPE_BOOLEAN, False, fn=fn, l=arg.args[0].value, name=name,
652
+ r=arg.args[2].value, value=args[1].value)
653
+ return None
634
654
 
635
655
 
636
656
  def _ascii_lower(s):
@@ -1101,6 +1121,18 @@ class Evaluator:
1101
1121
  return raw is not None and at.attr_equals(raw, e.value) != e.negate
1102
1122
  if op == E_ATTR_EXISTS:
1103
1123
  return self.attribute_of(node, e.name) is not None
1124
+ if op == E_ATTR_TEST:
1125
+ # a missing attribute is an empty node-set, whose string-value is ""
1126
+ raw = self.attribute_of(node, e.name) or ""
1127
+ if dec.needs_decoding(raw):
1128
+ raw = dec.decode(raw, True)
1129
+ value = e.l + raw + e.r if e.l or e.r else raw
1130
+ fn = e.fn
1131
+ if fn == "contains":
1132
+ return e.value in value
1133
+ if fn == "starts-with":
1134
+ return value.startswith(e.value)
1135
+ return value.endswith(e.value)
1104
1136
  return _to_boolean(self.eval_expr(e, node, position, size))
1105
1137
 
1106
1138
  def eval_predicate(self, e, node, position, size):
@@ -1116,7 +1148,7 @@ class Evaluator:
1116
1148
  op = e.op
1117
1149
  if op == E_LITERAL or op == E_NUMBER:
1118
1150
  return e.value
1119
- if op in (E_AND, E_OR, E_COMPARE, E_ATTR_EQUALS, E_ATTR_EXISTS):
1151
+ if op in (E_AND, E_OR, E_COMPARE, E_ATTR_EQUALS, E_ATTR_EXISTS, E_ATTR_TEST):
1120
1152
  return self.eval_bool(e, node, position, size)
1121
1153
  if op == E_ARITH:
1122
1154
  x = self.eval_number(e.l, node, position, size)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fasthtmlparser-pure
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Fast HTML / XML parser for scraping with XPath 1.0 and CSS selectors, in pure Python. A port of z3l.FastHtmlParser.
5
5
  Author: z3l
6
6
  License-Expression: LicenseRef-z3l-FastHtmlParser
@@ -28,6 +28,8 @@ Dynamic: license-file
28
28
  [![CI](https://github.com/romanti3172/fasthtmlparser-pure/actions/workflows/ci.yml/badge.svg)](https://github.com/romanti3172/fasthtmlparser-pure/actions/workflows/ci.yml)
29
29
  [![PyPI](https://img.shields.io/pypi/v/fasthtmlparser-pure.svg)](https://pypi.org/project/fasthtmlparser-pure/)
30
30
 
31
+ **Website:** [fasthtmlparser.com](https://fasthtmlparser.com): try the parser on any page, documentation and every language.
32
+
31
33
  A fast HTML / XML parser for scraping, with **XPath 1.0** and **CSS selectors**, in **pure Python**: a port of
32
34
  [z3l.FastHtmlParser](https://github.com/romanti3172/z3l.FastHtmlParser) with no compiled code and no dependencies. It
33
35
  is built for extracting data, not for building a DOM: a page becomes a flat list of tags that hold only positions in
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "fasthtmlparser-pure"
7
- version = "0.1.1"
7
+ version = "0.1.2"
8
8
  description = "Fast HTML / XML parser for scraping with XPath 1.0 and CSS selectors, in pure Python. A port of z3l.FastHtmlParser."
9
9
  readme = "README.md"
10
10
  license = "LicenseRef-z3l-FastHtmlParser"