diff --git a/extruct/jsonld.py b/extruct/jsonld.py index 989ac04..d25a418 100644 --- a/extruct/jsonld.py +++ b/extruct/jsonld.py @@ -33,7 +33,9 @@ def extract_items(self, document, base_url=None): ] def _extract_items(self, node): - script = node.xpath("string()") + script = node.xpath("string()").strip() + if not script: + return try: # TODO: `strict=False` can be configurable if needed data = json.loads(script, strict=False) diff --git a/tests/test_jsonld.py b/tests/test_jsonld.py index d274b3d..178b322 100644 --- a/tests/test_jsonld.py +++ b/tests/test_jsonld.py @@ -63,3 +63,9 @@ def test_null(self): jsonlde = JsonLdExtractor() data = jsonlde.extract(body) self.assertEqual(data, expected) + + def test_empty_jsonld_script(self): + jsonlde = JsonLdExtractor() + body = '' + data = jsonlde.extract(body) + self.assertEqual(data, [])