Skip to content

Commit

Permalink
Merge pull request psf#205 from leven-cn/develop
Browse files Browse the repository at this point in the history
Add "tag" attribute for Element objects
  • Loading branch information
kennethreitz committed Sep 18, 2018
2 parents 95a113c + 1c21f63 commit 87b183c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,19 @@ 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'
Show the line number that an :class:`Element <Element>`'s root tag located in:

.. code-block:: pycon
>>> about.lineno
249
Select an :class:`Element <Element>` list within an :class:`Element <Element>`:

Expand Down
2 changes: 2 additions & 0 deletions requests_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ 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.lineno = element.sourceline
self._attrs = None

def __repr__(self) -> str:
Expand Down

0 comments on commit 87b183c

Please sign in to comment.