Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions extruct/jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ def extract(self, htmlstring, base_url=None, encoding="UTF-8"):
return self.extract_items(tree, base_url=base_url)

def extract_items(self, document, base_url=None):
return [item for items in map(self._extract_items,
self._xp_jsonld(document))
for item in items
if item]
return [
item
for items in map(self._extract_items, self._xp_jsonld(document))
if items for item in items if item
]

def _extract_items(self, node):
script = node.xpath('string()')
Expand All @@ -33,7 +34,8 @@ def _extract_items(self, node):
data = json.loads(script, strict=False)
except ValueError:
# sometimes JSON-decoding errors are due to leading HTML or JavaScript comments
data = json.loads(HTML_OR_JS_COMMENTLINE.sub('', script), strict=False)
data = json.loads(
HTML_OR_JS_COMMENTLINE.sub('', script), strict=False)
if isinstance(data, list):
return data
elif isinstance(data, dict):
Expand Down
Loading