4 ms·
Ignoring the memo part here and focusing on having None/empty list as a return value, what is the problem of doing: soup.find('table', {'class':'search-par
by rglullis 16y ago
Ignoring the memo part here and focusing on having None/empty list as a return value, what is the problem of doing:
soup.find('table', {'class':'search-params'}).findParent('form')\
.find('td', {'class': 'elem'})\
.find('input')\
.get('name') or raise WebUIError("Web interface specification changed")
Shouldn't the boolean expression short-circuit and only raise WebUIError in case the expression returns what he doesn't want to?
- natrius 16y agoAny of those find calls can return None. None does not have a find method.
- jey 16y agoThis sounds more like a design flaw in BeautifulSoup than anything else. The OP is wrong in directing his anger towards NULL/None/nil. (BeautifulSoup should be returning an empty collection, not None.)
- njharman 16y agoBingo! This api fail drives me crazy when using BS. Esp since it's otherwise pretty slick.
- rglullis 16y agoOh, you're absolutely right. I thought that BeautifulSoup's find would be lazily evaluated, like Django's Queryset.