blob: 258d3a827ba8b5578f2b9a3f813a71d8d4bc9fba (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
Scrapers
========
A scraper extends the abstract :class:`~hircine.scraper.Scraper` class and
implements its :meth:`~hircine.scraper.Scraper.scrape` method. The latter is a
generator function yielding :ref:`scraped-data`.
.. autoclass:: hircine.scraper.Scraper
:members:
:special-members: __init__
Exceptions
----------
A scraper may raise two kinds of exceptions:
.. autoexception:: hircine.scraper.ScrapeWarning
.. autoexception:: hircine.scraper.ScrapeError
Utility functions
-----------------
.. automodule:: hircine.scraper.utils
:members:
Registering a scraper
---------------------
To register your class as a scraper, place it into the ``hircine.scraper``
:ref:`entry point group <packaging:entry-points>`. For example, put the
following in a ``pyproject.toml`` file:
.. code-block:: toml
[project.entry-points.'hircine.scraper']
my_scraper = 'myscraper.MyScraper'
Example
-------
.. literalinclude:: /_examples/example_scraper.py
:language: python
The scraper above will scrape a JSON file with the following structure:
.. literalinclude:: /_examples/example_scraper.json
:language: json
|