Skip to content

Commit e02eace

Browse files
committed
Fix a bug when head or html tags are not present
1 parent a91b73f commit e02eace

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

extruct/rdfa.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,12 @@ def _fix_order(self, jsonld_string, document):
112112
Fix order of rdfa tags in jsonld string
113113
by checking the appearance order in the HTML
114114
"""
115-
html_element = document.xpath('/html')[0]
116-
head_element = document.xpath('//head')[0]
115+
json_objects = json.loads(jsonld_string)
116+
117+
html, head = document.xpath('/html'), document.xpath('//head')
118+
if not html or not head:
119+
return json_objects
120+
html_element, head_element = html[0], head[0]
117121

118122
# Stores the values or each property in appearance order
119123
values_for_property = defaultdict(list)
@@ -123,8 +127,6 @@ def _fix_order(self, jsonld_string, document):
123127
html_element,
124128
head_element)
125129
values_for_property[expanded_property].append(meta_tag.get('content'))
126-
127-
json_objects = json.loads(jsonld_string)
128130

129131
for json_object in json_objects:
130132
keys = json_object.keys()

0 commit comments

Comments
 (0)