Skip to content

Commit

Permalink
Merge pull request #426 from elifesciences/develop
Browse files Browse the repository at this point in the history
PR for version 0.35.0 release
  • Loading branch information
gnott committed Nov 6, 2023
2 parents 9064f03 + 5901df2 commit 754a8fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion elifetools/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.34.0"
__version__ = "0.35.0"
15 changes: 12 additions & 3 deletions elifetools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,19 @@ def extract_nodes(soup, nodename, attr=None, value=None):
Returns a list of tags (nodes) from the given soup matching the given nodename.
If an optional attribute and value are given, these are used to filter the results
further."""
tags = soup.find_all(nodename)
# convert string value to list
if isinstance(nodename, str):
nodename = [nodename]
if attr is not None and value is not None:
return list(filter(lambda tag: tag.get(attr) == value, tags))
return list(tags)
# filter nodes by tag namd and attribute name
return [
tag
for tag in soup.descendants
if tag.name in nodename and tag.get(attr) == value
]
else:
# filter nodes by tag name only
return [tag for tag in soup.descendants if tag.name in nodename]


def node_text(tag):
Expand Down

0 comments on commit 754a8fe

Please sign in to comment.