Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
lxml の xpath() 関数は通常、要素のリストを返します。
正確に 1 つの要素を返すことが期待される XPath がある場合、最も適切な方法は次のとおりです。
SQLAlchemy の one() 関数の類似物を本当に探しています。
try: (element,) = tree.xpath('//xpath/selector') except ValueError: raise InvalidSelector() # happened because the list was either empty or contained multiple elements