Sync-First бібліотека для побудови графу веб-сайтів - просто як requests!
Project description
GraphCrawler
Бібліотека для побудови графу структури веб-сайтів.
Встановлення
pip install graph-crawler
Додаткові залежності:
pip install graph-crawler[playwright] # JavaScript сайти
pip install graph-crawler[embeddings] # Векторизація
pip install graph-crawler[mongodb] # MongoDB storage
pip install graph-crawler[all] # Все
Використання
import graph_crawler as gc
# Базове сканування
graph = gc.crawl("https://example.com", max_depth=2, max_pages=50)
print(f"Сторінок: {len(graph.nodes)}")
print(f"Посилань: {len(graph.edges)}")
# Збереження
gc.save_graph(graph, "site.json")
Async API
import asyncio
import graph_crawler as gc
async def main():
graph = await gc.async_crawl("https://example.com")
return graph
graph = asyncio.run(main())
Параметри crawl()
| Параметр | Default | Опис |
|---|---|---|
max_depth |
3 | Глибина сканування |
max_pages |
100 | Ліміт сторінок |
same_domain |
True | Тільки поточний домен |
request_delay |
0.5 | Затримка між запитами (сек) |
timeout |
300 | Загальний таймаут (сек) |
driver |
"http" | Драйвер: http, playwright |
URL Rules
from graph_crawler import crawl, URLRule
rules = [
URLRule(pattern=r"\.pdf$", should_scan=False),
URLRule(pattern=r"/admin/", should_scan=False),
URLRule(pattern=r"/products/", priority=10),
]
graph = crawl("https://example.com", url_rules=rules)
Операції з графом
# Статистика
stats = graph.get_stats()
# Пошук
node = graph.get_node_by_url("https://example.com/page")
# Об'єднання графів
merged = graph1 + graph2
# Експорт
graph.export_edges("edges.csv", format="csv")
graph.export_edges("graph.dot", format="dot")
Драйвери
| Драйвер | Призначення |
|---|---|
http |
Статичні сайти (default) |
playwright |
JavaScript/SPA сайти |
# Playwright для JS сайтів
graph = gc.crawl("https://spa-site.com", driver="playwright")
Storage
| Тип | Рекомендовано |
|---|---|
memory |
< 1K сторінок |
json |
1K - 20K сторінок |
sqlite |
20K+ сторінок |
mongodb |
Великі проекти |
CLI
graph-crawler crawl https://example.com --max-depth 2
graph-crawler list
graph-crawler info graph_name
Вимоги
- Python 3.11+
Ліцензія
MIT
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
graph_crawler-4.0.14.tar.gz
(720.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graph_crawler-4.0.14.tar.gz.
File metadata
- Download URL: graph_crawler-4.0.14.tar.gz
- Upload date:
- Size: 720.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d10116934d2bf0c5908f1c4893793a88bfe4de71bbcc1803dea318a95360514a
|
|
| MD5 |
3b0676b7a63f6bfde418ddb902791071
|
|
| BLAKE2b-256 |
65d1e386d81850bbb9dea2261ec382b54e9b25a6b2604f6ef0a7bad8f97e1341
|
File details
Details for the file graph_crawler-4.0.14-py3-none-any.whl.
File metadata
- Download URL: graph_crawler-4.0.14-py3-none-any.whl
- Upload date:
- Size: 862.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc447193c45f60fd7281df7eee2aa2ceda1dd8e1c3e474819c28e029740a5e2c
|
|
| MD5 |
b89bd40f53f91585deefe2fd4f126958
|
|
| BLAKE2b-256 |
6641a5055ab055b34a558a5c7a2b5a467c35da485164cbc2687ee015cae670bb
|