brozzler/job-conf.rst

504 lines
16 KiB
ReStructuredText
Raw Normal View History

2018-03-19 14:14:37 -07:00
Brozzler Job Configuration
2016-09-29 16:15:44 -07:00
**************************
2018-03-19 14:14:37 -07:00
Jobs are defined using yaml files. At least one seed url must be specified,
everything else is optional.
2018-03-19 14:14:37 -07:00
.. contents::
Example
=======
::
id: myjob
time_limit: 60 # seconds
2018-03-19 14:14:37 -07:00
proxy: 127.0.0.1:8000 # point at warcprox for archiving
ignore_robots: false
max_claimed_sites: 2
warcprox_meta:
warc-prefix: job1
stats:
buckets:
- job1-stats
metadata: {}
seeds:
- url: http://one.example.org/
warcprox_meta:
warc-prefix: job1-seed1
stats:
buckets:
- job1-seed1-stats
- url: http://two.example.org/
time_limit: 30
- url: http://three.example.org/
time_limit: 10
ignore_robots: true
scope:
surt: http://(org,example,
2018-03-19 14:14:37 -07:00
How inheritance works
2016-09-29 16:15:44 -07:00
=====================
Most of the settings that apply to seeds can also be specified at the top
level, in which case all seeds inherit those settings. If an option is
specified both at the top level and at seed level, the results are merged with
the seed-level value taking precedence in case of conflicts. It's probably
easiest to make sense of this by way of an example.
In the example yaml above, ``warcprox_meta`` is specified at the top level and
at the seed level for the seed http://one.example.org/. At the top level we
have::
warcprox_meta:
warc-prefix: job1
stats:
buckets:
- job1-stats
At the seed level we have::
warcprox_meta:
warc-prefix: job1-seed1
stats:
buckets:
- job1-seed1-stats
The merged configuration as applied to the seed http://one.example.org/ will
be::
warcprox_meta:
warc-prefix: job1-seed1
stats:
buckets:
- job1-stats
- job1-seed1-stats
Notice that:
- There is a collision on ``warc-prefix`` and the seed-level value wins.
- Since ``buckets`` is a list, the merged result includes all the values from
both the top level and the seed level.
2016-09-29 16:15:44 -07:00
2018-03-20 17:31:42 -07:00
Settings
========
2016-09-29 16:15:44 -07:00
2018-03-19 14:14:37 -07:00
Top-level settings
------------------
2017-06-23 13:56:25 -07:00
``id``
2018-03-19 14:14:37 -07:00
~~~~~~
+--------+----------+--------------------------+
| type | required | default |
+========+==========+==========================+
| string | no | *generated by rethinkdb* |
+--------+----------+--------------------------+
2016-09-29 16:15:44 -07:00
An arbitrary identifier for this job. Must be unique across this deployment of
brozzler.
``max_claimed_sites``
2018-03-19 14:14:37 -07:00
~~~~~~~~~~~~~~~~~~~~~
+--------+----------+---------+
| type | required | default |
+========+==========+=========+
| number | no | *none* |
+--------+----------+---------+
Puts a cap on the number of sites belonging to a given job that can be brozzled
simultaneously across the cluster. Addresses the problem of a job with many
seeds starving out other jobs.
2018-03-19 14:14:37 -07:00
``seeds``
~~~~~~~~~
+------------------------+----------+---------+
| type | required | default |
+========================+==========+=========+
| list (of dictionaries) | yes | *n/a* |
+------------------------+----------+---------+
List of seeds. Each item in the list is a dictionary (associative array) which
defines the seed. It must specify ``url`` (see below) and can additionally
specify any seed settings.
2018-03-19 14:14:37 -07:00
Seed-level-only settings
------------------------
These settings can be specified only at the seed level, unlike most seed
settings, which can also be specified at the top level.
2017-06-23 13:56:25 -07:00
``url``
2018-03-19 14:14:37 -07:00
~~~~~~~
+--------+----------+---------+
| type | required | default |
+========+==========+=========+
| string | yes | *n/a* |
+--------+----------+---------+
The seed url. Crawling starts here.
2016-09-29 16:15:44 -07:00
2018-03-19 14:14:37 -07:00
``username``
~~~~~~~~~~~~
+--------+----------+---------+
| type | required | default |
+========+==========+=========+
| string | no | *none* |
+--------+----------+---------+
If set, used to populate automatically detected login forms. See explanation at
"password" below.
2018-03-19 14:14:37 -07:00
``password``
~~~~~~~~~~~~
+--------+----------+---------+
| type | required | default |
+========+==========+=========+
| string | no | *none* |
+--------+----------+---------+
If set, used to populate automatically detected login forms. If ``username``
and ``password`` are configured for a seed, brozzler will look for a login form
on each page it crawls for that seed. A form that has a single text or email
field (the username), a single password field (``<input type="password">``),
and has ``method="POST"`` is considered to be a login form. The form may have
other fields like checkboxes and hidden fields. For these, brozzler will leave
the default values in place. Brozzler submits login forms after page load.
Then brozzling proceeds as usual.
2018-03-19 14:14:37 -07:00
Seed-level / top-level settings
-------------------------------
These are seed settings that can also be speficied at the top level, in which
case they are inherited by all seeds.
2017-06-23 13:56:25 -07:00
``metadata``
2018-03-19 14:14:37 -07:00
~~~~~~~~~~~~
+------------+----------+---------+
| type | required | default |
+============+==========+=========+
| dictionary | no | *none* |
2018-03-19 14:14:37 -07:00
+------------+----------+---------+
Arbitrary information about the crawl job or site. Merely informative, not used
by brozzler for anything. Could be of use to some external process.
2017-06-23 13:56:25 -07:00
``time_limit``
2018-03-19 14:14:37 -07:00
~~~~~~~~~~~~~~
+--------+----------+---------+
| type | required | default |
+========+==========+=========+
| number | no | *none* |
+--------+----------+---------+
Time limit in seconds. If not specified, there is no time limit. Time limit is
2016-09-29 16:15:44 -07:00
enforced at the seed level. If a time limit is specified at the top level, it
is inherited by each seed as described above, and enforced individually on each
seed.
2018-03-19 14:14:37 -07:00
``proxy``
~~~~~~~~~
+--------+----------+---------+
| type | required | default |
+========+==========+=========+
| string | no | *none* |
+--------+----------+---------+
HTTP proxy, with the format ``host:port``. Typically configured to point to
warcprox for archival crawling.
2017-06-23 13:56:25 -07:00
``ignore_robots``
2018-03-19 14:14:37 -07:00
~~~~~~~~~~~~~~~~~
+---------+----------+-----------+
| type | required | default |
+=========+==========+===========+
| boolean | no | ``false`` |
+---------+----------+-----------+
2016-09-29 16:15:44 -07:00
If set to ``true``, brozzler will happily crawl pages that would otherwise be
blocked by robots.txt rules.
2017-06-23 13:56:25 -07:00
``user_agent``
2018-03-19 14:14:37 -07:00
~~~~~~~~~~~~~~
+---------+----------+---------+
| type | required | default |
+=========+==========+=========+
| string | no | *none* |
+---------+----------+---------+
The ``User-Agent`` header brozzler will send to identify itself to web servers.
It's good ettiquette to include a project URL with a notice to webmasters that
explains why you're crawling, how to block the crawler robots.txt and how to
contact the operator if the crawl is causing problems.
2017-06-23 13:56:25 -07:00
``warcprox_meta``
2018-03-19 14:14:37 -07:00
~~~~~~~~~~~~~~~~~
+------------+----------+-----------+
| type | required | default |
+============+==========+===========+
| dictionary | no | ``false`` |
+------------+----------+-----------+
2018-05-30 18:06:39 -07:00
Specifies the ``Warcprox-Meta`` header to send with every request, if ``proxy``
is configured. The value of the ``Warcprox-Meta`` header is a json blob. It is
used to pass settings and information to warcprox. Warcprox does not forward
the header on to the remote site. For full documentation on ``warcprox-meta``
see https://github.com/internetarchive/warcprox/blob/master/api.rst#warcprox-meta-http-request-header
2016-09-29 16:15:44 -07:00
Brozzler takes the configured value of ``warcprox_meta``, converts it to
json and populates the Warcprox-Meta header with that value. For example::
warcprox_meta:
warc-prefix: job1-seed1
stats:
buckets:
- job1-stats
- job1-seed1-stats
becomes::
Warcprox-Meta: {"warc-prefix":"job1-seed1","stats":{"buckets":["job1-stats","job1-seed1-stats"]}}
2017-06-23 13:56:25 -07:00
``scope``
2018-03-19 14:14:37 -07:00
~~~~~~~~~
+------------+----------+-----------+
| type | required | default |
+============+==========+===========+
| dictionary | no | ``false`` |
+------------+----------+-----------+
Scope specificaion for the seed. See the "Scoping" section which follows.
2017-06-23 13:56:25 -07:00
2018-03-19 14:14:37 -07:00
Scoping
=======
The scope of a seed determines which links are scheduled for crawling and which
are not. Example::
scope:
accepts:
2018-05-14 17:31:45 -07:00
- ssurt: com,example,//https:/
- parent_url_regex: ^https?://(www\.)?youtube.com/(user|channel)/.*$
regex: ^https?://(www\.)?youtube.com/watch\?.*$
- surt: http://(com,google,video,
- surt: http://(com,googlevideo,
blocks:
- domain: youngscholars.unimelb.edu.au
substring: wp-login.php?action=logout
- domain: malware.us
max_hops: 20
2018-03-22 17:18:36 -07:00
max_hops_off: 0
2018-03-19 14:14:37 -07:00
2018-03-20 17:31:42 -07:00
Toward the end of the process of brozzling a page, brozzler obtains a list of
navigational links (``<a href="...">`` and similar) on the page, and evaluates
each link to determine whether it is in scope or out of scope for the crawl.
Then, newly discovered links that are in scope are scheduled to be crawled, and
previously discovered links get a priority bump.
How brozzler applies scope rules
--------------------------------
2018-05-14 17:31:45 -07:00
Each scope rule has one or more conditions. If all of the conditions match,
then the scope rule as a whole matches. For example::
- domain: youngscholars.unimelb.edu.au
substring: wp-login.php?action=logout
This rule applies if the domain of the url is "youngscholars.unimelb.edu.au" or
a subdomain, and the string "wp-login.php?action=logout" is found somewhere in
the url.
Brozzler applies these logical steps to decide whether a url is in or out of
scope:
2018-05-14 17:31:45 -07:00
1. If the number of hops from seed is greater than ``max_hops``, the url is
**out of scope**.
2. Otherwise, if any ``block`` rule matches, the url is **out of scope**.
3. Otherwise, if any ``accept`` rule matches, the url is **in scope**.
4. Otherwise, if the url is at most ``max_hops_off`` hops from the last page
that was in scope thanks to an ``accept`` rule, the url is **in scope**.
5. Otherwise (no rules match), the url is **out of scope**.
2018-05-14 17:31:45 -07:00
Notably, ``block`` rules take precedence over ``accept`` rules.
It may also be helpful to think about a list of scope rules as a boolean
expression. For example::
blocks:
- domain: youngscholars.unimelb.edu.au
substring: wp-login.php?action=logout
- domain: malware.us
means block the url IF::
("domain: youngscholars.unimelb.edu.au" AND "substring: wp-login.php?action=logout") OR "domain: malware.us"
Automatic scoping based on seed urls
------------------------------------
Brozzler usually generates an ``accept`` scope rule based on the seed url. It
does this to fulfill the usual expectation that everything "under" the seed
will be crawled.
To generate the rule, brozzler canonicalizes the seed url using the `urlcanon
<https://github.com/iipc/urlcanon>`_ library's "semantic" canonicalizer, then
removes the query string if any, and finally serializes the result in SSURT
[1]_ form. For example, a seed url of
2018-03-20 17:31:42 -07:00
``https://www.EXAMPLE.com:443/foo//bar?a=b&c=d#fdiap`` becomes
``com,example,www,//https:/foo/bar?a=b&c=d``.
2018-03-20 17:31:42 -07:00
If the url in the browser location bar at the end of brozzling the seed page
differs from the seed url, brozzler automatically adds a second ``accept`` rule
to ensure the site is in scope, as if the new url were the original seed url.
2018-03-20 17:31:42 -07:00
It does this so that, for example, if ``http://example.com/`` redirects to
``http://www.example.com/``, the rest of the ``www.example.com`` is in scope.
2018-03-20 17:31:42 -07:00
Brozzler derives its general approach to the seed surt from Heritrix, but
differs in a few respects.
1. Unlike heritrix, brozzler does not strip the path segment after the last
slash.
2. Canonicalization does not attempt to match heritrix exactly, though it
usually does match.
3. When generating a surt for an https url, heritrix changes the scheme to
2018-03-20 17:31:42 -07:00
http. For example, the heritrix surt for ``https://www.example.com/`` is
``http://(com,example,www,)`` and this means that all of
``http://www.example.com/*`` and ``https://www.example.com/*`` are in
scope. It also means that a manually specified surt with scheme "https" does
2018-03-20 17:31:42 -07:00
not match anything. Brozzler does no scheme munging.
4. Brozzler identifies seed "redirects" by retrieving the url from the
browser's location bar at the end of brozzling the seed page, whereas
heritrix follows http 3xx redirects.
5. Brozzler uses ssurt instead of surt.
6. There is currently no brozzler option to disable the automatically generated
``accept`` rules.
Scope settings
--------------
2017-06-23 13:56:25 -07:00
``accepts``
2018-03-19 14:14:37 -07:00
~~~~~~~~~~~
+------+----------+---------+
| type | required | default |
+======+==========+=========+
| list | no | *none* |
+------+----------+---------+
List of scope rules. If any of the rules match, and the url is within
``max_hops`` from seed, and none of the ``block`` rules apply, the url is in
scope.
2017-06-23 13:56:25 -07:00
``blocks``
2018-03-19 14:14:37 -07:00
~~~~~~~~~~~
+------+----------+---------+
| type | required | default |
+======+==========+=========+
| list | no | *none* |
+------+----------+---------+
List of scope rules. If any of the rules match, the url is deemed out of scope.
2018-03-19 14:14:37 -07:00
``max_hops``
~~~~~~~~~~~~
+--------+----------+---------+
| type | required | default |
+========+==========+=========+
| number | no | *none* |
+--------+----------+---------+
Maximum number of hops from seed.
2018-03-22 17:18:36 -07:00
``max_hops_off``
2018-05-14 17:31:45 -07:00
~~~~~~~~~~~~~~~~
+--------+----------+---------+
| type | required | default |
+========+==========+=========+
| number | no | 0 |
+--------+----------+---------+
Expands the scope to include urls up to this many hops from the last page that
was in scope thanks to an ``accept`` rule.
2018-03-19 14:14:37 -07:00
2018-05-14 17:31:45 -07:00
Scope rule conditions
---------------------
2018-03-19 14:14:37 -07:00
``domain``
~~~~~~~~~
+--------+----------+---------+
| type | required | default |
+========+==========+=========+
| string | no | *none* |
+--------+----------+---------+
Matches if the host part of the canonicalized url is ``domain`` or a
subdomain.
2018-03-19 14:14:37 -07:00
``substring``
~~~~~~~~~~~~~
+--------+----------+---------+
| type | required | default |
+========+==========+=========+
| string | no | *none* |
+--------+----------+---------+
Matches if ``substring`` is found anywhere in the canonicalized url.
2018-03-19 14:14:37 -07:00
``regex``
~~~~~~~~~
+--------+----------+---------+
| type | required | default |
+========+==========+=========+
| string | no | *none* |
+--------+----------+---------+
Matches if the full canonicalized url matches ``regex``.
2018-03-19 14:14:37 -07:00
``ssurt``
~~~~~~~~~
+--------+----------+---------+
| type | required | default |
+========+==========+=========+
| string | no | *none* |
+--------+----------+---------+
Matches if the canonicalized url in SSURT [1]_ form starts with ``ssurt``.
2017-06-23 13:56:25 -07:00
2018-03-19 14:14:37 -07:00
``surt``
~~~~~~~~
+--------+----------+---------+
| type | required | default |
+========+==========+=========+
| string | no | *none* |
+--------+----------+---------+
Matches if the canonicalized url in SURT [2]_ form starts with ``surt``.
2018-03-19 14:14:37 -07:00
``parent_url_regex``
~~~~~~~~~~~~~~~~~~~~
+--------+----------+---------+
| type | required | default |
+========+==========+=========+
| string | no | *none* |
+--------+----------+---------+
Matches if the full canonicalized parent url matches ``regex``. The parent url
is the url of the page in which the link was found.
2017-06-23 13:56:25 -07:00
2018-05-30 18:06:39 -07:00
Using ``warcprox_meta``
=======================
``warcprox_meta`` deserves some more discussion. It plays a very important role
in brozzler job configuration. ``warcprox_meta`` is the way you set the
filenames of the warcs for your crawl. For example, if each seed should have a
different warc name prefix, you might have a job configured this way::
seeds:
- url: https://example.com/
warcprox_meta:
warc-prefix: seed1
- url: https://archive.org/
warcprox_meta:
warc-prefix: seed2
``warcprox_meta`` is also the way to put limits on the size of the crawl job.
For example, this configuration will stop the crawl after about 100 MB of novel
content has been crawled::
seeds:
- url: https://example.com/
- url: https://archive.org/
warcprox_meta:
stats:
buckets:
- my-job
limits:
my-job/new/wire_bytes: 100000000
To prevent any urls from a host from being captured, it's not sufficient to use
a ``scope`` rule as described above. That kind of scoping only applies to
navigational links discovered in crawled pages. To make absolutely sure no url
from a given host is fetched, not even (say) an image embedded in a page, use
``warcprox_meta`` like so::
warcprox_meta:
blocks:
- domain: spammy.com
For complete documentation on the ``warcprox-meta`` request header, see
https://github.com/internetarchive/warcprox/blob/master/api.rst#warcprox-meta-http-request-header
.. [1] SSURT is described at https://github.com/iipc/urlcanon/blob/master/ssurt.rst
.. [2] SURT is described at http://crawler.archive.org/articles/user_manual/glossary.html