Skip to content

Commit

Permalink
better docstrings
Browse files Browse the repository at this point in the history
Signed-off-by: Kenneth Reitz <me@kennethreitz.org>
  • Loading branch information
kennethreitz committed Feb 28, 2018
1 parent df39a9f commit aae5f13
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
37 changes: 33 additions & 4 deletions requests_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@


class BaseParser:
"""A basic HTML/Element Parser, for Humans."""
"""A basic HTML/Element Parser, for Humans.
:param element: The element from which to base the parsing upon.
:param default_encoding: Which encoding to default to.
:param html: HTML from which to base the parsing upon (optional).
:param url: The URL from which the HTML originated, used for ``absolute_links``.
"""

def __init__(self, *, element, default_encoding: str = None, html: str = None, url: str) -> None:
self.element = element
Expand Down Expand Up @@ -96,6 +103,9 @@ def full_text(self) -> str:
def find(self, selector: str, first: bool = False, _encoding: str = None):
"""Given a CSS Selector, returns a list of :class:`Element <Element>` objects.
:param selector: CSS Selector to use.
:param first: Whether or not to return just the first result.
Example CSS Selectors:
- ``a``
Expand Down Expand Up @@ -125,6 +135,9 @@ def xpath(self, selector: str, first: bool = False, _encoding: str = None):
"""Given an XPath selector, returns a list of
:class:`Element <Element>` objects.
:param selector: XPath Selector to use.
:param first: Whether or not to return just the first result.
If a sub-selector is specified (e.g. ``//a/@href``), a simple
list of results is returned.
Expand Down Expand Up @@ -153,12 +166,18 @@ def xpath(self, selector: str, first: bool = False, _encoding: str = None):
return c

def search(self, template: str) -> Result:
"""Searches the :class:`Element <Element>` for the given parse template."""
"""Searches the :class:`Element <Element>` for the given Parse template.
:param template: The Parse template to use.
"""

return parse_search(template, self.html)

def search_all(self, template: str) -> Result:
"""Searches the :class:`Element <Element>` (multiple times) for the given parse
template.
:param template: The Parse template to use.
"""
return [r for r in findall(template, self.html)]

Expand Down Expand Up @@ -221,7 +240,12 @@ def base_url(self) -> str:


class Element(BaseParser):
"""An element of HTML."""
"""An element of HTML.
:param element: The element from which to base the parsing upon.
:param url: The URL from which the HTML originated, used for ``absolute_links``.
:param default_encoding: Which encoding to default to.
"""

def __init__(self, *, element, url, default_encoding) -> None:
super(Element, self).__init__(element=element, url=url, default_encoding=default_encoding)
Expand Down Expand Up @@ -249,7 +273,12 @@ def attrs(self) -> dict:


class HTML(BaseParser):
"""An HTML document, ready for parsing."""
"""An HTML document, ready for parsing.
:param url: The URL from which the HTML originated, used for ``absolute_links``.
:param html: HTML from which to base the parsing upon (optional).
:param default_encoding: Which encoding to default to.
"""

def __init__(self, *, url=DEFAULT_URL, html, default_encoding=DEFAULT_ENCODING) -> None:

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
URL = 'https://github.com/kennethreitz/requests-html'
EMAIL = 'me@kennethreitz.org'
AUTHOR = 'Kenneth Reitz'
VERSION = '0.6.5'
VERSION = '0.6.6'

# What packages are required for this module to be executed?
REQUIRED = [
Expand Down

0 comments on commit aae5f13

Please sign in to comment.