Tag() comparisons

23 views
Skip to first unread message

Martin Evans

unread,
Aug 6, 2017, 6:00:03 PM8/6/17
to beautifulsoup

Is it possible to sort tags by the order they would be in the document tree?

This appears to work to a certain extent in some circumstances with the Python 2.x version but fails with the following error under Python 3.x

TypeError: unorderable types: Tag() < Tag()

The use case is being able to do multiple different types of soup.find_all() calls, append the results together and to then be able to sort the results such that the list is in document order.

Does a tag have some kind of index attribute which could be used as a sort key?

Kind regards,

Martin


Reply all
Reply to author
Forward
0 new messages