Commit 5b4cdf13 authored by Quentin Defenouillere's avatar Quentin Defenouillere Committed by ntome

[weboob/browser/elements] Implement the empty_xpath attribute

The empty_xpath attribute is used to fetch an explicit message on a page
when there is no account, no transaction or no investment for example.
The goal of this attribute is to avoid silent bugs when an item page has
completely changed and the item_xpath does not match any element
anymore: in these cases we don't scrape any element but we don't crash
either ; whereas if empty_xpath is defined at least we will have a
warning that the page may have changed.
parent 9aa87930
......@@ -155,6 +155,7 @@ class AbstractElement(object):
class ListElement(AbstractElement):
item_xpath = None
empty_xpath = None
flush_at_end = False
ignore_duplicate = False
......@@ -176,8 +177,13 @@ class ListElement(AbstractElement):
sufficient.
"""
if self.item_xpath is not None:
for el in self.el.xpath(self.item_xpath):
yield el
element_list = self.el.xpath(self.item_xpath)
if element_list:
for el in element_list:
yield el
elif self.empty_xpath is not None and not self.el.xpath(self.empty_xpath):
# Send a warning if no item_xpath node was found and an empty_xpath is defined
self.logger.warning('No element matched the item_xpath and the defined empty_xpath was not found!')
else:
yield self.el
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment