diff --git a/extruct/xmldom.py b/extruct/xmldom.py index fe0a03ba..018919c8 100644 --- a/extruct/xmldom.py +++ b/extruct/xmldom.py @@ -6,15 +6,22 @@ from xml.dom import Node from xml.dom.minidom import Attr, NamedNodeMap -from lxml.etree import ( - ElementBase, - XPath, - _ElementStringResult, - _ElementUnicodeResult, - tostring, -) +from lxml.etree import ElementBase, XPath, _ElementUnicodeResult, tostring from lxml.html import HtmlElementClassLookup, HTMLParser +try: + from lxml.etree import _ElementStringResult +except ImportError: + + class _ElementStringResult(bytes): # type: ignore[no-redef] + """ + _ElementStringResult is removed in lxml >= 5.1.1, + so we define it here for compatibility. + """ + + def getparent(self): + return self._parent # type: ignore[attr-defined] + class DomElementUnicodeResult: CDATA_SECTION_NODE = Node.CDATA_SECTION_NODE diff --git a/requirements.txt b/requirements.txt index aefa8e39..6665ca9a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ # project requirements, install them using following command: # pip install -r requirements.txt -lxml +lxml[html_clean] requests rdflib>=6.0.0; python_version>="3.7" rdflib<6.0.0; python_version<"3.7" diff --git a/tests/samples/misc/microformat_flat_test.json b/tests/samples/misc/microformat_flat_test.json index 28344b3d..60ad4827 100644 --- a/tests/samples/misc/microformat_flat_test.json +++ b/tests/samples/misc/microformat_flat_test.json @@ -32,7 +32,10 @@ "aJ Styles FastLane 2018 15 x 17 Framed Plaque w/ Ring Canvas" ], "photo": [ - "/on/demandware.static/-/Sites-main/default/dwa3227ee6/images/small/CN1148.jpg" + { + "alt": "aJ Styles FastLane 2018 15 x 17 Framed Plaque w/ Ring Canvas", + "value": "/on/demandware.static/-/Sites-main/default/dwa3227ee6/images/small/CN1148.jpg" + } ] } ] diff --git a/tests/samples/misc/microformat_test.json b/tests/samples/misc/microformat_test.json index a485db03..5eea845c 100644 --- a/tests/samples/misc/microformat_test.json +++ b/tests/samples/misc/microformat_test.json @@ -27,7 +27,11 @@ { "properties": { "photo": [ - "/on/demandware.static/-/Sites-main/default/dwa3227ee6/images/small/CN1148.jpg" + { + "alt": "aJ Styles FastLane 2018 15 x 17 Framed Plaque w/ Ring Canvas", + "value": "/on/demandware.static/-/Sites-main/default/dwa3227ee6/images/small/CN1148.jpg" + + } ], "name": [ "aJ Styles FastLane 2018 15 x 17 Framed Plaque w/ Ring Canvas" diff --git a/tests/test_uniform.py b/tests/test_uniform.py index ca27dd2c..81d92849 100644 --- a/tests/test_uniform.py +++ b/tests/test_uniform.py @@ -167,7 +167,10 @@ def test_umicroformat(self): "Canvas" ], "photo": [ - "/on/demandware.static/-/Sites-main/default/dwa3227ee6/images/small/CN1148.jpg" + { + "alt": "aJ Styles FastLane 2018 15 x 17 Framed Plaque w/ Ring Canvas", + "value": "/on/demandware.static/-/Sites-main/default/dwa3227ee6/images/small/CN1148.jpg", + } ], }, ],