Add "tag" attribute for Element object

This commit is contained in:
Li Yun
2018-07-04 11:20:08 +08:00
parent c59480bf15
commit 116a4b08eb
2 changed files with 6 additions and 0 deletions
+5
View File
@@ -103,7 +103,12 @@ Render out an :class:`Element <Element>`'s HTML:
>>> about.html
'<li aria-haspopup="true" class="tier-1 element-1 " id="about">\n<a class="" href="/about/" title="">About</a>\n<ul aria-hidden="true" class="subnav menu" role="menu">\n<li class="tier-2 element-1" role="treeitem"><a href="/about/apps/" title="">Applications</a></li>\n<li class="tier-2 element-2" role="treeitem"><a href="/about/quotes/" title="">Quotes</a></li>\n<li class="tier-2 element-3" role="treeitem"><a href="/about/gettingstarted/" title="">Getting Started</a></li>\n<li class="tier-2 element-4" role="treeitem"><a href="/about/help/" title="">Help</a></li>\n<li class="tier-2 element-5" role="treeitem"><a href="http://brochure.getpython.info/" title="">Python Brochure</a></li>\n</ul>\n</li>'
Crab an :class:`Element <Element>`'s root tag name:
.. code-block:: pycon
>>> about.tag
'li'
Select an :class:`Element <Element>` list within an :class:`Element <Element>`:
+1
View File
@@ -378,6 +378,7 @@ class Element(BaseParser):
def __init__(self, *, element, url: _URL, default_encoding: _DefaultEncoding = None) -> None:
super(Element, self).__init__(element=element, url=url, default_encoding=default_encoding)
self.element = element
self.tag = element.tag
self._attrs = None
def __repr__(self) -> str: