Skip to content

HRemonen/Webster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webster

Webster is an experimental python web scraping framework for my own learning.

Webster can be used to scrape or download webpages by giving a list of urls to visit and optionally a list of urls to stay within.

Webster could be used as a broad crawler also, but it is not optimized for that as of now.

Version

Webster has been tested using Python 3.10+

Project documentation

  1. Quick start guide
  2. Architectural model
  3. Functional specification
  4. Test documentation

Installation

Install Webster using pip install

pip install webster-crawler

Development

Webster is using Poetry as packaging and dependency manager.

Install dependencies using

poetry install

Remember to build the source and wheels archives when changes are made using

poetry build

Include all build changes etc. in PR.

Dependencies

Webster is using multiple external Python packages some of which are:

  • lxml used for processing html documents.
  • w3lib used for URL handling and prosessing.
  • pycURL used for networking and making requests to a http server.
  • pymongo tools for working with mongoDB using python

Remember to include all new dependencies in PRs and update readme etc accordingly.

Testing

Webster uses unittest for testing.

To run all the tests use the following command:

python -m unittest discover -v

Example: We want to test Parser module To run single module test use the following command:

python -m unittest test.test_parser -v

Coverage

To run test coverage use the coverage module

python -m coverage run -m unittest

To show coverage report in terminal

python -m coverage report

Output should look something like this.

Name                              Stmts   Miss  Cover
-----------------------------------------------------
test/__init__.py                      0      0   100%
test/test_data/__init__.py           10      0   100%
test/test_downloader.py              43      1    98%
test/test_parser.py                  54      1    98%
test/test_request.py                 49      2    96%
test/test_robotstxt.py               23      1    96%
test/test_url_tools.py               22      1    95%
test/test_validators.py              53      1    98%
webster/__init__.py                   0      0   100%
webster/conf/__init__.py              0      0   100%
webster/conf/settings.py              9      0   100%
webster/core/__init__.py              0      0   100%
webster/core/downloader.py           36      8    78%
webster/core/parser.py               40      1    98%
webster/net/__init__.py               0      0   100%
webster/net/request/__init__.py      47      2    96%
webster/pipelines/__init__.py         0      0   100%
webster/robotstxt.py                 15      2    87%
webster/utils/__init__.py             0      0   100%
webster/utils/url_tools.py           15      0   100%
webster/utils/validators.py          16      7    56%
-----------------------------------------------------
TOTAL                               432     27    94%

For a nicer report and more detailed use the html report

python -m coverage html

open htmlcov/index.html   

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

BSD 3-Clause License

Copyright (c) 2022, Henri Remonen. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.