A library for crawling websites
Project description
http-crawler is a library for crawling websites. It uses requests to speak HTTP.
Installation
Install with pip:
$ pip install http-crawler
Usage
The http_crawler module provides one generator function, crawl.
crawl is called with a URL, and yields instances of requests’s Response class.
crawl will request the page at the given URL, and will extract all URLs from the response. It will then make a request for each of those URLs, and will repeat the process until it has requested every URL linked to from pages on the original URL’s domain. It will not extract or process URLs from any page with a different domain to the original URL.
For instance, this is how you would use crawl to find and log any broken links on a site:
>>> from http_crawler import crawl
>>> for rsp in crawl('http://www.example.com'):
>>> if rsp.status_code != 200:
>>> print('Got {} at {}'.format(rsp.status_code, rsp.url))
crawl has a number of options:
follow_external_links (default True) If set, crawl will make a request for every URL it encounters, including ones with a different domain to the original URL. If not set, crawl will ignore all URLs that have a different domain to the original URL. In either case, crawl will not extract further URLs from a page with a different domain to the original URL.
ignore_fragments (default True) If set, crawl will ignore the fragment part of any URL. This means that if crawl encounters http://domain/path#anchor, it will make a request for http://domain/path. Moreover, it means that if crawl encounters http://domain/path#anchor1 and http://domain/path#anchor2, it will only make one request.
Motivation
Why another crawling library? There are certainly lots of Python tools for crawling websites, but all that I could find were either too complex, too simple, or had too many dependencies.
http-crawler is designed to be a library and not a framework, so it should be straightforward to use in applications or other libraries.
Contributing
There are a handful of enhancements on the issue tracker that would be suitable for somebody looking to contribute to Open Source for the first time.
For instructions about making Pull Requests, see GitHub’s guide.
All contributions should include tests with 100% code coverage, and should comply with PEP 8. The project uses tox for running tests and checking code quality metrics.
To run the tests:
$ tox
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file http-crawler-0.1.5.tar.gz
.
File metadata
- Download URL: http-crawler-0.1.5.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da889d6604a1ee2bf475eff6e8b848ef35ad4d5768db1eef1fa8912f9ce945e7 |
|
MD5 | b68506254b572c86aa42d48f7c494f05 |
|
BLAKE2b-256 | d950b9e301e785080251a1f7bda652fa6129721caa2bef6c725613b902800ea4 |