Skip to content

Commit 18f41f1

Browse files
authored
Merge pull request #96 from scrapinghub/fix-jsonld-return-none-bug
fix bug
2 parents b459dbf + fd7d67c commit 18f41f1

File tree

4 files changed

+1740
-6
lines changed

4 files changed

+1740
-6
lines changed

extruct/jsonld.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ def extract(self, htmlstring, base_url=None, encoding="UTF-8"):
2121
return self.extract_items(tree, base_url=base_url)
2222

2323
def extract_items(self, document, base_url=None):
24-
return [item for items in map(self._extract_items,
25-
self._xp_jsonld(document))
26-
for item in items
27-
if item]
24+
return [
25+
item
26+
for items in map(self._extract_items, self._xp_jsonld(document))
27+
if items for item in items if item
28+
]
2829

2930
def _extract_items(self, node):
3031
script = node.xpath('string()')
@@ -33,7 +34,8 @@ def _extract_items(self, node):
3334
data = json.loads(script, strict=False)
3435
except ValueError:
3536
# sometimes JSON-decoding errors are due to leading HTML or JavaScript comments
36-
data = json.loads(HTML_OR_JS_COMMENTLINE.sub('', script), strict=False)
37+
data = json.loads(
38+
HTML_OR_JS_COMMENTLINE.sub('', script), strict=False)
3739
if isinstance(data, list):
3840
return data
3941
elif isinstance(data, dict):

0 commit comments

Comments
 (0)