-
-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix index out of range when <body> or <head> is missing #272
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,15 +287,19 @@ def body(self): | |
Return the <body> element. Can be called from a child element | ||
to get the document's head. | ||
""" | ||
return self.xpath('//body|//x:body', namespaces={'x':XHTML_NAMESPACE})[0] | ||
result = self.xpath('//body|//x:body', namespaces={'x':XHTML_NAMESPACE}) | ||
if len(result) > 1: | ||
return result[0] | ||
|
||
@property | ||
def head(self): | ||
""" | ||
Returns the <head> element. Can be called from a child | ||
element to get the document's head. | ||
""" | ||
return self.xpath('//head|//x:head', namespaces={'x':XHTML_NAMESPACE})[0] | ||
result = self.xpath('//head|//x:head', namespaces={'x':XHTML_NAMESPACE}) | ||
if len(result) > 1: | ||
return result[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Otherwise … do what? Return None? Would be good to say so if that's what you want. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've some difficulty to run lxml tests, it's a bit new for me, and that pull request is a kind of experience. It should return None indeed, I can correct that. |
||
|
||
@property | ||
def label(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
> 1
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"> 0", because I'm stupid :p