From 1c21f636728aa2815c6fc2a598e2974a9c6026b9 Mon Sep 17 00:00:00 2001 From: Li Yun <3425791734@qq.com> Date: Wed, 4 Jul 2018 11:30:59 +0800 Subject: [PATCH] Add "lineno" attribute for Element object --- docs/source/index.rst | 7 +++++++ requests_html.py | 1 + 2 files changed, 8 insertions(+) diff --git a/docs/source/index.rst b/docs/source/index.rst index e6e2618..1e891d7 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -110,6 +110,13 @@ Crab an :class:`Element `'s root tag name: >>> about.tag 'li' +Show the line number that an :class:`Element `'s root tag located in: + +.. code-block:: pycon + + >>> about.lineno + 249 + Select an :class:`Element ` list within an :class:`Element `: .. code-block:: pycon diff --git a/requests_html.py b/requests_html.py index 134f432..42c1f8d 100644 --- a/requests_html.py +++ b/requests_html.py @@ -379,6 +379,7 @@ class Element(BaseParser): 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: