diff options
Diffstat (limited to 'bs4/element.py')
-rw-r--r-- | bs4/element.py | 45 |
1 files changed, 18 insertions, 27 deletions
diff --git a/bs4/element.py b/bs4/element.py index 2e101c4..7734f80 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -1318,46 +1318,37 @@ class Tag(PageElement): current = current.next_element # CSS selector code - def select_one(self, selector, namespaces=None, flags=0): - """Perform a CSS selection operation on the current element""" - value = self.select(selector, namespaces, 1, flags) + def select_one(self, selector, namespaces=None, **kwargs): + """Perform a CSS selection operation on the current element.""" + value = self.select(selector, namespaces, 1, **kwargs) if value: return value[0] return None - def select(self, selector, namespaces=None, limit=None, flags=0): - """ - Perform a CSS selection operation on the current element. - - A "namespaces" dictionary that provides prefixes with the associated - namespaces is requied (along with a parser that accounts for - namespaces) in order for namespace syntax to work "prefix|tag". - - The dictionary is akin to using "@namespace" in CSS. + def select(self, selector, namespaces=None, limit=None, **kwargs): + """Perform a CSS selection operation on the current element. - /* Default namespace */ - @namespace url(XML-namespace-URL); - /* Prefixed namespace */ - @namespace prefix url(XML-namespace-URL); + This uses the SoupSieve library. - So in a dictionary, the followig would be equivalent + :param selector: A string containing a CSS selector. - { - # Default namespace - "": "XML-namespace-URL", + :param namespaces: A dictionary mapping namespace prefixes + used in the CSS selector to namespace URIs. By default, + Beautiful Soup will use the prefixes it encountered while + parsing the document. - # Prefixed namespace - "prefix": "XML-namespace-URL" - } + :param limit: After finding this number of results, stop looking. - Flags is reserved for if/when soupsieve requires flags for - additional feature control. + :param kwargs: Any extra arguments you'd like to pass in to + soupsieve.select(). """ - + if namespaces is None: + namespaces = self._namespaces + if limit is None: limit = 0 - return soupsieve.select(selector, self, namespaces, limit, flags) + return soupsieve.select(selector, self, namespaces, limit, **kwargs) # Old names for backwards compatibility def childGenerator(self): |