Arakneed
A common use targeted concurrent crawler for any directed graph. It's designed to be easy to use.
It's an adequate practice to organize your crawler code instead of a spider library or framework.
Why this since there's scrapy .etc?
Because they are not supposed to crawl my pictures on my laptop but I want to crawl them like a spider.
Arakneed can be used to traverse any directed graph, including a directory on your computer to collect pictures or collecting someone's all Github Gists... And anything looks like directed graph.
Though it can also be used to crawl a website like a tranditional spider.
Usage
Install as dependency:
pip install -U arakneed
Or you can clone the repo and work right in place within file crawler.py:
git clone https://github.com/arakneed/crawler.git
How does it work?
Any vertex spotted by the spider will be scheduled as a task. The only thing you need to do is to define how to handle the tasks.
import asyncio
from pathlib import Path
import re
import aiohttp
from arakneed import Crawler, Task
async def resolver(task: Task, response: aiohttp.ClientResponse):
if task.type == 'page':
r = await response.text()
return [
Task('image', group[1])
for group in re.compile(r'<img.+?src=\"(.+?)\".*?>').finditer(r)
if group[1].endswith('.jpg') or group[1].endswith('.png') or group[1].endswith('.svg')
]
if task.type == 'image':
image_path = Path('~/Downloads/gh-images', task.key.split('/')[-1]).expanduser()
if not image_path.parent.is_dir():
image_path.parent.mkdir()
image_path.touch()
image_path.write_bytes(await response.content.read())
asyncio.run(Crawler().run(Task('page', 'https://github.com'), resolver))
This code downloads all images it founds on Github. I believe it explains what does the business code look like.
Examples
- Crawl a website
- Collect pictures in a local driver
- Abstract Syntax Tree analyzer
MISC
- Be careful with circles in the directed graph if you are customizing the scheduler/spider. The framework always checks whether all corresponding vertices are resolved recursively of every vertex to know when could it have a relax :)
- This paradigm is not distributed. Though you can take a glance of it through Redis based vertices resolving check, but the task is locked as soon as it's resolved, you cannot resolve a task on several machines simultaneously.
Development
A branch called dev is recommended for common development.
Useful commands:
- install poetry
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
source $HOME/.poetry/env - install dependencies
poetry install - run tests
poetry run pytest - lint
poetry run flake8 --max-line-length=120 --statistics
Metadata
Release files for arakneed 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| arakneed-0.3.0.tar.gz | 8.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| arakneed-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.1 kB
Release files / arakneed-0.3.0.tar.gz
| Download URL | arakneed-0.3.0.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
60ceeb2686b9b88cc1cc043a4412692248b646417f47e93ddf26f215e76885d5
|
|
BLAKE2b-256 checksum How to use checksums |
e92ba6ad7fcc37b894f03a0de427aa85552c28dcf3fc1a73ef334f9baa572c9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.12
|
Release files / arakneed-0.3.0-py3-none-any.whl
| Download URL | arakneed-0.3.0-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ec158fac378753e22a8e651378f258d1293ec79246f8a0ec91e97f653c1688af
|
|
BLAKE2b-256 checksum How to use checksums |
6d40a6031816fa0589d9d25e41a28e887baf770b70c238d76c2eb8e94ccbac56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.12
|
Security for arakneed 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.