티스토리 수익 글 보기
{{ message }}
Fix index out of range when <body> or <head> is missing – #272
Closed
FVolral wants to merge 1 commit into
Closed
Conversation
If a HTML file that doesn't contain <body> is parsed, it can lead to a index out of range error when you try getattr(lxmlElement, "body") for example.
scoder
reviewed
Sep 2, 2018
scoder
left a comment
Member
There was a problem hiding this comment.
Generally a good idea, but the implementation needs fixing. Would have been obvious with some tests (hint, hint).
| 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] |
Member
There was a problem hiding this comment.
Otherwise … do what? Return None? Would be good to say so if that’s what you want.
Author
There was a problem hiding this comment.
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.
| """ | ||
| 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: |
Member
|
No problem. To start the tests, it should be enough to run |
charshack
approved these changes
Jul 10, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If a HTML file that doesn’t contain a or part is parsed,
it can lead to a index out of range error when you try
getattr(lxmlElement, "body")