Skip to content

How to handle optional element Error #30

Answered by jamesturk
ghbook asked this question in Q&A
Discussion options

You must be logged in to vote

can you just catch the SelectorError like a normal exception?

try:
   year = XPath('.//td[5]').match_one(item).text
except SelectorError:
   year = None

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by jamesturk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants
Converted from issue

This discussion was converted from issue #29 on December 27, 2021 16:55.