dungscraper 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dungscraper-0.6.0/LICENSE +21 -0
- dungscraper-0.6.0/PKG-INFO +181 -0
- dungscraper-0.6.0/README.md +120 -0
- dungscraper-0.6.0/pyproject.toml +84 -0
- dungscraper-0.6.0/setup.cfg +4 -0
- dungscraper-0.6.0/src/dungscraper/__init__.py +6 -0
- dungscraper-0.6.0/src/dungscraper/__main__.py +4 -0
- dungscraper-0.6.0/src/dungscraper/adapters/__init__.py +57 -0
- dungscraper-0.6.0/src/dungscraper/adapters/arxiv.py +80 -0
- dungscraper-0.6.0/src/dungscraper/adapters/github.py +86 -0
- dungscraper-0.6.0/src/dungscraper/adapters/hackernews.py +107 -0
- dungscraper-0.6.0/src/dungscraper/adapters/reddit.py +1679 -0
- dungscraper-0.6.0/src/dungscraper/adapters/wikipedia.py +60 -0
- dungscraper-0.6.0/src/dungscraper/adapters/youtube.py +271 -0
- dungscraper-0.6.0/src/dungscraper/api/__init__.py +1 -0
- dungscraper-0.6.0/src/dungscraper/api/app.py +197 -0
- dungscraper-0.6.0/src/dungscraper/api/auth.py +29 -0
- dungscraper-0.6.0/src/dungscraper/api/routes.py +380 -0
- dungscraper-0.6.0/src/dungscraper/api/usage.py +121 -0
- dungscraper-0.6.0/src/dungscraper/banner.py +65 -0
- dungscraper-0.6.0/src/dungscraper/cli.py +584 -0
- dungscraper-0.6.0/src/dungscraper/client.py +117 -0
- dungscraper-0.6.0/src/dungscraper/config.py +117 -0
- dungscraper-0.6.0/src/dungscraper/core/__init__.py +1 -0
- dungscraper-0.6.0/src/dungscraper/core/batch.py +69 -0
- dungscraper-0.6.0/src/dungscraper/core/cache.py +136 -0
- dungscraper-0.6.0/src/dungscraper/core/chunk.py +139 -0
- dungscraper-0.6.0/src/dungscraper/core/clip.py +90 -0
- dungscraper-0.6.0/src/dungscraper/core/contacts.py +474 -0
- dungscraper-0.6.0/src/dungscraper/core/content.py +522 -0
- dungscraper-0.6.0/src/dungscraper/core/crawl.py +264 -0
- dungscraper-0.6.0/src/dungscraper/core/crawl_scoring.py +126 -0
- dungscraper-0.6.0/src/dungscraper/core/css_extract.py +180 -0
- dungscraper-0.6.0/src/dungscraper/core/dedupe.py +62 -0
- dungscraper-0.6.0/src/dungscraper/core/diff.py +36 -0
- dungscraper-0.6.0/src/dungscraper/core/documents.py +54 -0
- dungscraper-0.6.0/src/dungscraper/core/escalate.py +362 -0
- dungscraper-0.6.0/src/dungscraper/core/extract.py +282 -0
- dungscraper-0.6.0/src/dungscraper/core/feeds.py +277 -0
- dungscraper-0.6.0/src/dungscraper/core/fetch.py +601 -0
- dungscraper-0.6.0/src/dungscraper/core/focus.py +156 -0
- dungscraper-0.6.0/src/dungscraper/core/joblinks.py +309 -0
- dungscraper-0.6.0/src/dungscraper/core/jobs.py +293 -0
- dungscraper-0.6.0/src/dungscraper/core/limiter.py +34 -0
- dungscraper-0.6.0/src/dungscraper/core/map.py +113 -0
- dungscraper-0.6.0/src/dungscraper/core/mx.py +47 -0
- dungscraper-0.6.0/src/dungscraper/core/pagetools.py +71 -0
- dungscraper-0.6.0/src/dungscraper/core/proxies.py +164 -0
- dungscraper-0.6.0/src/dungscraper/core/research.py +336 -0
- dungscraper-0.6.0/src/dungscraper/core/robots.py +99 -0
- dungscraper-0.6.0/src/dungscraper/core/scrape.py +507 -0
- dungscraper-0.6.0/src/dungscraper/core/search.py +295 -0
- dungscraper-0.6.0/src/dungscraper/core/sitemap.py +82 -0
- dungscraper-0.6.0/src/dungscraper/core/sites.py +462 -0
- dungscraper-0.6.0/src/dungscraper/core/structured.py +64 -0
- dungscraper-0.6.0/src/dungscraper/core/urls.py +157 -0
- dungscraper-0.6.0/src/dungscraper/core/watch.py +173 -0
- dungscraper-0.6.0/src/dungscraper/errors.py +29 -0
- dungscraper-0.6.0/src/dungscraper/install_claude.py +110 -0
- dungscraper-0.6.0/src/dungscraper/local.py +200 -0
- dungscraper-0.6.0/src/dungscraper/log.py +42 -0
- dungscraper-0.6.0/src/dungscraper/mcp_server.py +695 -0
- dungscraper-0.6.0/src/dungscraper/models.py +676 -0
- dungscraper-0.6.0/src/dungscraper/playground.py +278 -0
- dungscraper-0.6.0/src/dungscraper/py.typed +0 -0
- dungscraper-0.6.0/src/dungscraper/security.py +49 -0
- dungscraper-0.6.0/src/dungscraper/services.py +107 -0
- dungscraper-0.6.0/src/dungscraper/worker.py +33 -0
- dungscraper-0.6.0/src/dungscraper.egg-info/PKG-INFO +181 -0
- dungscraper-0.6.0/src/dungscraper.egg-info/SOURCES.txt +90 -0
- dungscraper-0.6.0/src/dungscraper.egg-info/dependency_links.txt +1 -0
- dungscraper-0.6.0/src/dungscraper.egg-info/entry_points.txt +2 -0
- dungscraper-0.6.0/src/dungscraper.egg-info/requires.txt +33 -0
- dungscraper-0.6.0/src/dungscraper.egg-info/top_level.txt +1 -0
- dungscraper-0.6.0/tests/test_adapters.py +351 -0
- dungscraper-0.6.0/tests/test_api.py +287 -0
- dungscraper-0.6.0/tests/test_autoplius_watch.py +185 -0
- dungscraper-0.6.0/tests/test_cli.py +41 -0
- dungscraper-0.6.0/tests/test_contacts.py +208 -0
- dungscraper-0.6.0/tests/test_escalate.py +127 -0
- dungscraper-0.6.0/tests/test_integration.py +86 -0
- dungscraper-0.6.0/tests/test_interstitial.py +200 -0
- dungscraper-0.6.0/tests/test_joblinks.py +86 -0
- dungscraper-0.6.0/tests/test_local.py +35 -0
- dungscraper-0.6.0/tests/test_mcp.py +36 -0
- dungscraper-0.6.0/tests/test_reddit.py +630 -0
- dungscraper-0.6.0/tests/test_round2.py +197 -0
- dungscraper-0.6.0/tests/test_skelbiu.py +122 -0
- dungscraper-0.6.0/tests/test_units.py +283 -0
- dungscraper-0.6.0/tests/test_v02.py +85 -0
- dungscraper-0.6.0/tests/test_v050.py +240 -0
- dungscraper-0.6.0/tests/test_v060.py +968 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DungScraper contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dungscraper
|
|
3
|
+
Version: 0.6.0
|
|
4
|
+
Summary: Local-first web access for AI agents: scrape, crawl, search, research and extract. MCP server, REST API and CLI. No API key.
|
|
5
|
+
Author: DungScraper contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/dakisxxx-oss/DungScraper
|
|
8
|
+
Project-URL: Repository, https://github.com/dakisxxx-oss/DungScraper
|
|
9
|
+
Project-URL: Documentation, https://github.com/dakisxxx-oss/DungScraper/blob/main/docs/REFERENCE.md
|
|
10
|
+
Project-URL: Changelog, https://github.com/dakisxxx-oss/DungScraper/releases
|
|
11
|
+
Project-URL: Issues, https://github.com/dakisxxx-oss/DungScraper/issues
|
|
12
|
+
Keywords: mcp,mcp-server,web-scraping,web-crawler,ai-agents,llm,rag,markdown,firecrawl-alternative,research-agent,playwright,proxy-rotation
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Environment :: Console
|
|
16
|
+
Classifier: Framework :: FastAPI
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.11
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: fastapi>=0.115
|
|
30
|
+
Requires-Dist: uvicorn[standard]>=0.32
|
|
31
|
+
Requires-Dist: httpx[socks]>=0.27
|
|
32
|
+
Requires-Dist: pydantic>=2.9
|
|
33
|
+
Requires-Dist: pydantic-settings>=2.6
|
|
34
|
+
Requires-Dist: trafilatura>=2.0
|
|
35
|
+
Requires-Dist: readability-lxml>=0.8
|
|
36
|
+
Requires-Dist: beautifulsoup4>=4.12
|
|
37
|
+
Requires-Dist: lxml>=5
|
|
38
|
+
Requires-Dist: markdownify>=1.1
|
|
39
|
+
Requires-Dist: playwright>=1.48
|
|
40
|
+
Requires-Dist: pymupdf>=1.24
|
|
41
|
+
Requires-Dist: mammoth>=1.8
|
|
42
|
+
Requires-Dist: redis>=5.0
|
|
43
|
+
Requires-Dist: jsonschema>=4.23
|
|
44
|
+
Requires-Dist: typer>=0.12
|
|
45
|
+
Requires-Dist: mcp>=1.9
|
|
46
|
+
Requires-Dist: protego>=0.3
|
|
47
|
+
Requires-Dist: python-multipart>=0.0.9
|
|
48
|
+
Requires-Dist: curl_cffi>=0.7
|
|
49
|
+
Requires-Dist: dnspython>=2.6
|
|
50
|
+
Provides-Extra: dev
|
|
51
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
52
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
|
|
53
|
+
Requires-Dist: python-docx>=1.1; extra == "dev"
|
|
54
|
+
Requires-Dist: pyyaml>=6; extra == "dev"
|
|
55
|
+
Provides-Extra: stealth
|
|
56
|
+
Requires-Dist: curl_cffi>=0.7; extra == "stealth"
|
|
57
|
+
Requires-Dist: patchright>=1.49; extra == "stealth"
|
|
58
|
+
Requires-Dist: camoufox>=0.4; extra == "stealth"
|
|
59
|
+
Requires-Dist: seleniumbase>=4.34; extra == "stealth"
|
|
60
|
+
Dynamic: license-file
|
|
61
|
+
|
|
62
|
+
<p align="center"><img src="https://raw.githubusercontent.com/dakisxxx-oss/DungScraper/main/docs/hero.svg" alt="DungScraper" width="100%"></p>
|
|
63
|
+
|
|
64
|
+
<p align="center">
|
|
65
|
+
<img alt="version" src="https://img.shields.io/badge/version-0.6.0-2dd4bf">
|
|
66
|
+
<img alt="license" src="https://img.shields.io/badge/license-MIT-f59e0b">
|
|
67
|
+
<img alt="python" src="https://img.shields.io/badge/python-3.11%2B-3776ab">
|
|
68
|
+
<img alt="tests" src="https://img.shields.io/badge/tests-213%20passing-22c55e">
|
|
69
|
+
<img alt="MCP" src="https://img.shields.io/badge/MCP-ready-818cf8">
|
|
70
|
+
<img alt="no api key" src="https://img.shields.io/badge/API%20key-not%20needed-f472b6">
|
|
71
|
+
</p>
|
|
72
|
+
|
|
73
|
+
**DungScraper gives AI agents the web.** Scrape, crawl, search, and pull structured data from any page, on your own machine. There is no account, no API key and no per-page bill.
|
|
74
|
+
|
|
75
|
+
<p align="center"><img src="https://raw.githubusercontent.com/dakisxxx-oss/DungScraper/main/docs/demo.svg" alt="terminal demo" width="100%"></p>
|
|
76
|
+
|
|
77
|
+
## 30-second quickstart
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install git+https://github.com/dakisxxx-oss/DungScraper.git
|
|
81
|
+
python -m playwright install chromium # only needed for JavaScript-heavy pages
|
|
82
|
+
dungscraper doctor # checks your setup
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Add it to Claude Desktop, Cursor or any MCP client:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{ "mcpServers": { "dungscraper": { "command": "dungscraper", "args": ["mcp"] } } }
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
For Claude Desktop, `dungscraper install-claude` writes that entry for you. Then ask your agent to read a page.
|
|
92
|
+
|
|
93
|
+
> **Your agent will say it is using DungScraper.** Every tool result starts with `🦴 DungScraper v0.6.0 · <tool> · <tier> · <ms>`, and the tool descriptions tell the agent to mention it. Set `DUNGSCRAPER_BANNER=0` to turn the line off.
|
|
94
|
+
|
|
95
|
+
## What you get
|
|
96
|
+
|
|
97
|
+
| | |
|
|
98
|
+
|---|---|
|
|
99
|
+
| **Clean Markdown** | Main content with tables, code and links. HTTP first, a real browser when the page needs JavaScript. |
|
|
100
|
+
| **Token-budget reading** | `read_focused` ranks sections by your question (BM25) and returns only what fits. The demo above sends 278 tokens instead of 12,069. |
|
|
101
|
+
| **Extraction with no LLM** | `extract_fields` takes a CSS or XPath schema, with lists and nesting, and returns JSON. Fast, free and repeatable. |
|
|
102
|
+
| **Research with citations** | `research` searches, reads the top pages, follows promising links within a page and time budget, and returns ranked passages with source URLs and a cited brief. No LLM needed. Add your own OpenAI or Anthropic key for a written answer. |
|
|
103
|
+
| **Deep crawl strategies** | `bfs`, `dfs` or `best_first` crawling. Links are scored by keywords in the text and URL, depth, freshness and same-site authority. Include/exclude patterns, content-type filter, `min_score`. |
|
|
104
|
+
| **Proxies and scale** | Bring your own proxies (HTTP or SOCKS) with per-site stickiness, health tracking, backoff, and retry on 403/429 with the next proxy, on both the HTTP and browser paths. Batch scrape up to 200 URLs with global and per-host limits and spacing. Optional disk cache. |
|
|
105
|
+
| **Self-host ready** | Dockerfile with health check, compose file, API keys, per-key rate limits, `/v1/usage`, and Render, Fly and Railway templates. See [DEPLOY.md](https://github.com/dakisxxx-oss/DungScraper/blob/main/docs/DEPLOY.md). |
|
|
106
|
+
| **Crawl, map, search** | Crawl a site, list its URLs, search the web. |
|
|
107
|
+
| **Change watching** | `watch_page_tool` reports new, removed and price-changed ads, or a diff of any page. |
|
|
108
|
+
| **Site readers** | Reddit with no API key, RSS/Atom, skelbiu.lt and autoplius.lt listings, schema.org and OpenGraph on any page. |
|
|
109
|
+
| **Hard pages** | Waits out "preparing your page" interstitials, falls back to Chrome or Edge, supports actions and screenshots. |
|
|
110
|
+
| **Three ways in** | MCP server, REST API (Firecrawl-style `/v1/scrape`, plus `GET /r/<url>` like Jina Reader), and a CLI and Python SDK. |
|
|
111
|
+
| **Polite and private** | Respects robots.txt, listens on 127.0.0.1, blocks private-network targets by default. |
|
|
112
|
+
|
|
113
|
+
## How it compares
|
|
114
|
+
|
|
115
|
+
Based on each project's public docs, November 2026. Pricing changes, so check the source. See [docs/COMPETITORS.md](https://github.com/dakisxxx-oss/DungScraper/blob/main/docs/COMPETITORS.md) for details and sources.
|
|
116
|
+
|
|
117
|
+
| | **DungScraper** | Firecrawl | Crawl4AI | WaterCrawl | Jina Reader |
|
|
118
|
+
|---|---|---|---|---|---|
|
|
119
|
+
| Cost | Free, MIT | Free 1,000 credits, then from $19/mo | Free, open source | Free 1,000 credits hosted, or self-host | Free 20 req/min, then tokens |
|
|
120
|
+
| API key needed | **No** | Yes | No | Yes (hosted) | Optional |
|
|
121
|
+
| Runs on your machine | **Yes, one `pip install`** | Self-host is heavy | Yes | Docker stack (Postgres, Redis) | No |
|
|
122
|
+
| MCP server | Yes, local, no key | Yes | Yes, via Docker | Yes, needs a key | Hosted MCP |
|
|
123
|
+
| Scrape, crawl, map, search | Yes | Yes | Crawl, no search | Yes | Read and search |
|
|
124
|
+
| Query-focused, token-budgeted output | **Yes, no LLM** | LLM extraction, extra credits | Yes (BM25 and LLM filters) | No | No |
|
|
125
|
+
| CSS/XPath extraction with no LLM | **Yes** | No | Yes | No | No |
|
|
126
|
+
| Change watching | **Yes** | Change tracking, uses credits | No | No | No |
|
|
127
|
+
| Reddit with no key, local classifieds | **Yes** | No | No | No | No |
|
|
128
|
+
| Proxy rotation and scale | **Yes (bring your own proxies)** | Yes, managed | Yes (bring your own) | Yes (proxy management) | Hosted |
|
|
129
|
+
| Autonomous research agent | **Yes (retrieval with citations, no LLM; optional LLM answer)** | Yes (LLM agent, credits) | Partial (adaptive crawling) | No | No |
|
|
130
|
+
| Deep-crawl scoring strategies | **Yes (bfs, dfs, best-first, 4 scorers)** | Path filters and depth | Yes (more scorers and filters) | No | No |
|
|
131
|
+
| Hosted option | **Yes (self-host, Docker)** | Yes | Cloud and Docker | Yes | Yes |
|
|
132
|
+
|
|
133
|
+
"No" means not found in the project's public docs.
|
|
134
|
+
|
|
135
|
+
Where it loses, plainly:
|
|
136
|
+
- **Proxies are yours.** DungScraper rotates and health-checks proxies you supply. It sells and bundles none, and has no residential pool. Heavy bot protection (Cloudflare Turnstile, DataDome) can still block it.
|
|
137
|
+
- **Research is retrieval, not reasoning.** It ranks and cites passages. It does not click, log in or plan like Firecrawl's agent. A written answer needs your own model key.
|
|
138
|
+
- **"Hosted" means self-hosted.** The Docker image, compose file and one-click templates are ready, but there is no service run by us. The Docker build and platform deploys were not run from this repo's CI, so check your first deploy.
|
|
139
|
+
- **Scale is one machine** (or a few replicas whose rate-limit counters are separate). Crawl4AI's deep-crawl scorers and filters are more numerous than ours.
|
|
140
|
+
- It is a young project with fewer users and less mileage than the others.
|
|
141
|
+
|
|
142
|
+
## MCP tools
|
|
143
|
+
|
|
144
|
+
`scrape` · `batch_scrape` · `crawl` · `crawl_status` · `map_site` · `search_web` · `research` · `extract` · `chunk_text` · `reddit` · `read_feed` · `watch_page_tool` · `read_focused` · `extract_fields` · `find_contacts_tool` · `find_jobs_tool`
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
dungscraper scrape https://example.com --local # Markdown
|
|
148
|
+
dungscraper focus https://en.wikipedia.org/wiki/Web_scraping "is it legal" --max-tokens 300
|
|
149
|
+
dungscraper extract-css https://news.ycombinator.com --schema '{"baseSelector":"tr.athing","title":".titleline > a"}'
|
|
150
|
+
dungscraper research "How does BM25 ranking work?" --max-pages 5
|
|
151
|
+
dungscraper crawl https://example.com --local --strategy best_first --keywords "pricing,plans" --limit 10
|
|
152
|
+
dungscraper batch https://example.com https://example.org --concurrency 4 --per-host 1 --delay-ms 500
|
|
153
|
+
DUNGSCRAPER_PROXIES="http://user:pass@proxy1:8080,socks5://proxy2:1080" dungscraper scrape https://example.com --local
|
|
154
|
+
dungscraper watch https://www.skelbiu.lt/skelbimai/transportas/dviraciai/
|
|
155
|
+
curl "http://127.0.0.1:8741/r/https://example.com?query=pricing&max_tokens=500" # after: dungscraper serve
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
The full reference is in [docs/REFERENCE.md](https://github.com/dakisxxx-oss/DungScraper/blob/main/docs/REFERENCE.md).
|
|
159
|
+
|
|
160
|
+
## Roadmap
|
|
161
|
+
|
|
162
|
+
- [ ] Publish to PyPI
|
|
163
|
+
- [ ] Scheduled `watch` with email or Telegram alerts
|
|
164
|
+
- [ ] More local site readers (aruodas.lt, other classifieds)
|
|
165
|
+
- [ ] An LLM-driven browsing agent on top of `research`
|
|
166
|
+
- [ ] A managed hosted service (only if there is demand)
|
|
167
|
+
|
|
168
|
+
## Support the project
|
|
169
|
+
|
|
170
|
+
DungScraper is free and stays free to run on your own machine.
|
|
171
|
+
|
|
172
|
+
- **Star the repo.** It helps other people find it.
|
|
173
|
+
- **Run your own hosted instance today.** See [DEPLOY.md](https://github.com/dakisxxx-oss/DungScraper/blob/main/docs/DEPLOY.md).
|
|
174
|
+
- **Want a managed service run for you?** [Open an issue titled "Hosted waitlist"](https://github.com/dakisxxx-oss/DungScraper/issues/new?title=Hosted%20waitlist) to get in line. It is only built if enough people ask.
|
|
175
|
+
- **Need it for your business?** Open an issue for custom site readers, integration help or support.
|
|
176
|
+
|
|
177
|
+
## Use it responsibly
|
|
178
|
+
|
|
179
|
+
Respect each site's terms and robots.txt. DungScraper never extracts private seller phone numbers and refuses what robots.txt disallows. See [SECURITY.md](https://github.com/dakisxxx-oss/DungScraper/blob/main/SECURITY.md).
|
|
180
|
+
|
|
181
|
+
MIT licensed. See [LICENSE](https://github.com/dakisxxx-oss/DungScraper/blob/main/LICENSE).
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/dakisxxx-oss/DungScraper/main/docs/hero.svg" alt="DungScraper" width="100%"></p>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img alt="version" src="https://img.shields.io/badge/version-0.6.0-2dd4bf">
|
|
5
|
+
<img alt="license" src="https://img.shields.io/badge/license-MIT-f59e0b">
|
|
6
|
+
<img alt="python" src="https://img.shields.io/badge/python-3.11%2B-3776ab">
|
|
7
|
+
<img alt="tests" src="https://img.shields.io/badge/tests-213%20passing-22c55e">
|
|
8
|
+
<img alt="MCP" src="https://img.shields.io/badge/MCP-ready-818cf8">
|
|
9
|
+
<img alt="no api key" src="https://img.shields.io/badge/API%20key-not%20needed-f472b6">
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
**DungScraper gives AI agents the web.** Scrape, crawl, search, and pull structured data from any page, on your own machine. There is no account, no API key and no per-page bill.
|
|
13
|
+
|
|
14
|
+
<p align="center"><img src="https://raw.githubusercontent.com/dakisxxx-oss/DungScraper/main/docs/demo.svg" alt="terminal demo" width="100%"></p>
|
|
15
|
+
|
|
16
|
+
## 30-second quickstart
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install git+https://github.com/dakisxxx-oss/DungScraper.git
|
|
20
|
+
python -m playwright install chromium # only needed for JavaScript-heavy pages
|
|
21
|
+
dungscraper doctor # checks your setup
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Add it to Claude Desktop, Cursor or any MCP client:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{ "mcpServers": { "dungscraper": { "command": "dungscraper", "args": ["mcp"] } } }
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
For Claude Desktop, `dungscraper install-claude` writes that entry for you. Then ask your agent to read a page.
|
|
31
|
+
|
|
32
|
+
> **Your agent will say it is using DungScraper.** Every tool result starts with `🦴 DungScraper v0.6.0 · <tool> · <tier> · <ms>`, and the tool descriptions tell the agent to mention it. Set `DUNGSCRAPER_BANNER=0` to turn the line off.
|
|
33
|
+
|
|
34
|
+
## What you get
|
|
35
|
+
|
|
36
|
+
| | |
|
|
37
|
+
|---|---|
|
|
38
|
+
| **Clean Markdown** | Main content with tables, code and links. HTTP first, a real browser when the page needs JavaScript. |
|
|
39
|
+
| **Token-budget reading** | `read_focused` ranks sections by your question (BM25) and returns only what fits. The demo above sends 278 tokens instead of 12,069. |
|
|
40
|
+
| **Extraction with no LLM** | `extract_fields` takes a CSS or XPath schema, with lists and nesting, and returns JSON. Fast, free and repeatable. |
|
|
41
|
+
| **Research with citations** | `research` searches, reads the top pages, follows promising links within a page and time budget, and returns ranked passages with source URLs and a cited brief. No LLM needed. Add your own OpenAI or Anthropic key for a written answer. |
|
|
42
|
+
| **Deep crawl strategies** | `bfs`, `dfs` or `best_first` crawling. Links are scored by keywords in the text and URL, depth, freshness and same-site authority. Include/exclude patterns, content-type filter, `min_score`. |
|
|
43
|
+
| **Proxies and scale** | Bring your own proxies (HTTP or SOCKS) with per-site stickiness, health tracking, backoff, and retry on 403/429 with the next proxy, on both the HTTP and browser paths. Batch scrape up to 200 URLs with global and per-host limits and spacing. Optional disk cache. |
|
|
44
|
+
| **Self-host ready** | Dockerfile with health check, compose file, API keys, per-key rate limits, `/v1/usage`, and Render, Fly and Railway templates. See [DEPLOY.md](https://github.com/dakisxxx-oss/DungScraper/blob/main/docs/DEPLOY.md). |
|
|
45
|
+
| **Crawl, map, search** | Crawl a site, list its URLs, search the web. |
|
|
46
|
+
| **Change watching** | `watch_page_tool` reports new, removed and price-changed ads, or a diff of any page. |
|
|
47
|
+
| **Site readers** | Reddit with no API key, RSS/Atom, skelbiu.lt and autoplius.lt listings, schema.org and OpenGraph on any page. |
|
|
48
|
+
| **Hard pages** | Waits out "preparing your page" interstitials, falls back to Chrome or Edge, supports actions and screenshots. |
|
|
49
|
+
| **Three ways in** | MCP server, REST API (Firecrawl-style `/v1/scrape`, plus `GET /r/<url>` like Jina Reader), and a CLI and Python SDK. |
|
|
50
|
+
| **Polite and private** | Respects robots.txt, listens on 127.0.0.1, blocks private-network targets by default. |
|
|
51
|
+
|
|
52
|
+
## How it compares
|
|
53
|
+
|
|
54
|
+
Based on each project's public docs, November 2026. Pricing changes, so check the source. See [docs/COMPETITORS.md](https://github.com/dakisxxx-oss/DungScraper/blob/main/docs/COMPETITORS.md) for details and sources.
|
|
55
|
+
|
|
56
|
+
| | **DungScraper** | Firecrawl | Crawl4AI | WaterCrawl | Jina Reader |
|
|
57
|
+
|---|---|---|---|---|---|
|
|
58
|
+
| Cost | Free, MIT | Free 1,000 credits, then from $19/mo | Free, open source | Free 1,000 credits hosted, or self-host | Free 20 req/min, then tokens |
|
|
59
|
+
| API key needed | **No** | Yes | No | Yes (hosted) | Optional |
|
|
60
|
+
| Runs on your machine | **Yes, one `pip install`** | Self-host is heavy | Yes | Docker stack (Postgres, Redis) | No |
|
|
61
|
+
| MCP server | Yes, local, no key | Yes | Yes, via Docker | Yes, needs a key | Hosted MCP |
|
|
62
|
+
| Scrape, crawl, map, search | Yes | Yes | Crawl, no search | Yes | Read and search |
|
|
63
|
+
| Query-focused, token-budgeted output | **Yes, no LLM** | LLM extraction, extra credits | Yes (BM25 and LLM filters) | No | No |
|
|
64
|
+
| CSS/XPath extraction with no LLM | **Yes** | No | Yes | No | No |
|
|
65
|
+
| Change watching | **Yes** | Change tracking, uses credits | No | No | No |
|
|
66
|
+
| Reddit with no key, local classifieds | **Yes** | No | No | No | No |
|
|
67
|
+
| Proxy rotation and scale | **Yes (bring your own proxies)** | Yes, managed | Yes (bring your own) | Yes (proxy management) | Hosted |
|
|
68
|
+
| Autonomous research agent | **Yes (retrieval with citations, no LLM; optional LLM answer)** | Yes (LLM agent, credits) | Partial (adaptive crawling) | No | No |
|
|
69
|
+
| Deep-crawl scoring strategies | **Yes (bfs, dfs, best-first, 4 scorers)** | Path filters and depth | Yes (more scorers and filters) | No | No |
|
|
70
|
+
| Hosted option | **Yes (self-host, Docker)** | Yes | Cloud and Docker | Yes | Yes |
|
|
71
|
+
|
|
72
|
+
"No" means not found in the project's public docs.
|
|
73
|
+
|
|
74
|
+
Where it loses, plainly:
|
|
75
|
+
- **Proxies are yours.** DungScraper rotates and health-checks proxies you supply. It sells and bundles none, and has no residential pool. Heavy bot protection (Cloudflare Turnstile, DataDome) can still block it.
|
|
76
|
+
- **Research is retrieval, not reasoning.** It ranks and cites passages. It does not click, log in or plan like Firecrawl's agent. A written answer needs your own model key.
|
|
77
|
+
- **"Hosted" means self-hosted.** The Docker image, compose file and one-click templates are ready, but there is no service run by us. The Docker build and platform deploys were not run from this repo's CI, so check your first deploy.
|
|
78
|
+
- **Scale is one machine** (or a few replicas whose rate-limit counters are separate). Crawl4AI's deep-crawl scorers and filters are more numerous than ours.
|
|
79
|
+
- It is a young project with fewer users and less mileage than the others.
|
|
80
|
+
|
|
81
|
+
## MCP tools
|
|
82
|
+
|
|
83
|
+
`scrape` · `batch_scrape` · `crawl` · `crawl_status` · `map_site` · `search_web` · `research` · `extract` · `chunk_text` · `reddit` · `read_feed` · `watch_page_tool` · `read_focused` · `extract_fields` · `find_contacts_tool` · `find_jobs_tool`
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
dungscraper scrape https://example.com --local # Markdown
|
|
87
|
+
dungscraper focus https://en.wikipedia.org/wiki/Web_scraping "is it legal" --max-tokens 300
|
|
88
|
+
dungscraper extract-css https://news.ycombinator.com --schema '{"baseSelector":"tr.athing","title":".titleline > a"}'
|
|
89
|
+
dungscraper research "How does BM25 ranking work?" --max-pages 5
|
|
90
|
+
dungscraper crawl https://example.com --local --strategy best_first --keywords "pricing,plans" --limit 10
|
|
91
|
+
dungscraper batch https://example.com https://example.org --concurrency 4 --per-host 1 --delay-ms 500
|
|
92
|
+
DUNGSCRAPER_PROXIES="http://user:pass@proxy1:8080,socks5://proxy2:1080" dungscraper scrape https://example.com --local
|
|
93
|
+
dungscraper watch https://www.skelbiu.lt/skelbimai/transportas/dviraciai/
|
|
94
|
+
curl "http://127.0.0.1:8741/r/https://example.com?query=pricing&max_tokens=500" # after: dungscraper serve
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The full reference is in [docs/REFERENCE.md](https://github.com/dakisxxx-oss/DungScraper/blob/main/docs/REFERENCE.md).
|
|
98
|
+
|
|
99
|
+
## Roadmap
|
|
100
|
+
|
|
101
|
+
- [ ] Publish to PyPI
|
|
102
|
+
- [ ] Scheduled `watch` with email or Telegram alerts
|
|
103
|
+
- [ ] More local site readers (aruodas.lt, other classifieds)
|
|
104
|
+
- [ ] An LLM-driven browsing agent on top of `research`
|
|
105
|
+
- [ ] A managed hosted service (only if there is demand)
|
|
106
|
+
|
|
107
|
+
## Support the project
|
|
108
|
+
|
|
109
|
+
DungScraper is free and stays free to run on your own machine.
|
|
110
|
+
|
|
111
|
+
- **Star the repo.** It helps other people find it.
|
|
112
|
+
- **Run your own hosted instance today.** See [DEPLOY.md](https://github.com/dakisxxx-oss/DungScraper/blob/main/docs/DEPLOY.md).
|
|
113
|
+
- **Want a managed service run for you?** [Open an issue titled "Hosted waitlist"](https://github.com/dakisxxx-oss/DungScraper/issues/new?title=Hosted%20waitlist) to get in line. It is only built if enough people ask.
|
|
114
|
+
- **Need it for your business?** Open an issue for custom site readers, integration help or support.
|
|
115
|
+
|
|
116
|
+
## Use it responsibly
|
|
117
|
+
|
|
118
|
+
Respect each site's terms and robots.txt. DungScraper never extracts private seller phone numbers and refuses what robots.txt disallows. See [SECURITY.md](https://github.com/dakisxxx-oss/DungScraper/blob/main/SECURITY.md).
|
|
119
|
+
|
|
120
|
+
MIT licensed. See [LICENSE](https://github.com/dakisxxx-oss/DungScraper/blob/main/LICENSE).
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dungscraper"
|
|
7
|
+
version = "0.6.0"
|
|
8
|
+
description = "Local-first web access for AI agents: scrape, crawl, search, research and extract. MCP server, REST API and CLI. No API key."
|
|
9
|
+
readme = { file = "README.md", content-type = "text/markdown" }
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "DungScraper contributors" }]
|
|
14
|
+
keywords = [
|
|
15
|
+
"mcp", "mcp-server", "web-scraping", "web-crawler", "ai-agents", "llm", "rag", "markdown",
|
|
16
|
+
"firecrawl-alternative", "research-agent", "playwright", "proxy-rotation",
|
|
17
|
+
]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Development Status :: 4 - Beta",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"Environment :: Console",
|
|
22
|
+
"Framework :: FastAPI",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
"Programming Language :: Python :: 3",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Topic :: Internet :: WWW/HTTP :: Indexing/Search",
|
|
29
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
30
|
+
"Topic :: Text Processing :: Markup :: Markdown",
|
|
31
|
+
"Typing :: Typed",
|
|
32
|
+
]
|
|
33
|
+
dependencies = [
|
|
34
|
+
"fastapi>=0.115",
|
|
35
|
+
"uvicorn[standard]>=0.32",
|
|
36
|
+
"httpx[socks]>=0.27",
|
|
37
|
+
"pydantic>=2.9",
|
|
38
|
+
"pydantic-settings>=2.6",
|
|
39
|
+
"trafilatura>=2.0",
|
|
40
|
+
"readability-lxml>=0.8",
|
|
41
|
+
"beautifulsoup4>=4.12",
|
|
42
|
+
"lxml>=5",
|
|
43
|
+
"markdownify>=1.1",
|
|
44
|
+
"playwright>=1.48",
|
|
45
|
+
"pymupdf>=1.24",
|
|
46
|
+
"mammoth>=1.8",
|
|
47
|
+
"redis>=5.0",
|
|
48
|
+
"jsonschema>=4.23",
|
|
49
|
+
"typer>=0.12",
|
|
50
|
+
"mcp>=1.9",
|
|
51
|
+
"protego>=0.3",
|
|
52
|
+
"python-multipart>=0.0.9",
|
|
53
|
+
"curl_cffi>=0.7",
|
|
54
|
+
"dnspython>=2.6",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
[project.optional-dependencies]
|
|
58
|
+
dev = ["pytest>=8", "pytest-asyncio>=0.24", "python-docx>=1.1", "pyyaml>=6"]
|
|
59
|
+
stealth = ["curl_cffi>=0.7", "patchright>=1.49", "camoufox>=0.4", "seleniumbase>=4.34"]
|
|
60
|
+
|
|
61
|
+
[project.urls]
|
|
62
|
+
Homepage = "https://github.com/dakisxxx-oss/DungScraper"
|
|
63
|
+
Repository = "https://github.com/dakisxxx-oss/DungScraper"
|
|
64
|
+
Documentation = "https://github.com/dakisxxx-oss/DungScraper/blob/main/docs/REFERENCE.md"
|
|
65
|
+
Changelog = "https://github.com/dakisxxx-oss/DungScraper/releases"
|
|
66
|
+
Issues = "https://github.com/dakisxxx-oss/DungScraper/issues"
|
|
67
|
+
|
|
68
|
+
[project.scripts]
|
|
69
|
+
dungscraper = "dungscraper.cli:main"
|
|
70
|
+
|
|
71
|
+
[tool.setuptools.packages.find]
|
|
72
|
+
where = ["src"]
|
|
73
|
+
|
|
74
|
+
[tool.setuptools.package-data]
|
|
75
|
+
dungscraper = ["py.typed"]
|
|
76
|
+
|
|
77
|
+
[tool.pytest.ini_options]
|
|
78
|
+
asyncio_mode = "auto"
|
|
79
|
+
testpaths = ["tests"]
|
|
80
|
+
pythonpath = [".", "tests"]
|
|
81
|
+
markers = [
|
|
82
|
+
"integration: tests that fetch public pages on the internet",
|
|
83
|
+
]
|
|
84
|
+
filterwarnings = ["ignore::DeprecationWarning"]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""API-backed site adapters.
|
|
2
|
+
|
|
3
|
+
Each adapter reads a public API or a documented page format instead of the
|
|
4
|
+
generic HTML fetch. Optional adapters return None when they cannot handle a
|
|
5
|
+
URL, and the normal fetch continues. Reddit always handles its own URLs:
|
|
6
|
+
the official API when credentials are set, otherwise public JSON, then RSS,
|
|
7
|
+
then old.reddit HTML. It does not fall through to the generic fetcher.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from urllib.parse import urlsplit
|
|
13
|
+
|
|
14
|
+
import httpx
|
|
15
|
+
|
|
16
|
+
from dungscraper.adapters.arxiv import ArxivAdapter
|
|
17
|
+
from dungscraper.adapters.github import GitHubAdapter
|
|
18
|
+
from dungscraper.adapters.hackernews import HackerNewsAdapter
|
|
19
|
+
from dungscraper.adapters.reddit import REDDIT_SETUP, RedditAdapter
|
|
20
|
+
from dungscraper.adapters.wikipedia import WikipediaAdapter
|
|
21
|
+
from dungscraper.adapters.youtube import YouTubeAdapter
|
|
22
|
+
from dungscraper.config import Settings
|
|
23
|
+
from dungscraper.models import ScrapeData, ScrapeRequest
|
|
24
|
+
|
|
25
|
+
ADAPTERS = (
|
|
26
|
+
RedditAdapter(),
|
|
27
|
+
YouTubeAdapter(),
|
|
28
|
+
WikipediaAdapter(),
|
|
29
|
+
GitHubAdapter(),
|
|
30
|
+
ArxivAdapter(),
|
|
31
|
+
HackerNewsAdapter(),
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def adapter_for(url: str):
|
|
36
|
+
host = (urlsplit(url).hostname or "").lower()
|
|
37
|
+
if host.startswith("www."):
|
|
38
|
+
host = host[4:]
|
|
39
|
+
for adapter in ADAPTERS:
|
|
40
|
+
if adapter.matches(host, url):
|
|
41
|
+
return adapter
|
|
42
|
+
return None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
async def fetch_via_adapter(
|
|
46
|
+
request: ScrapeRequest,
|
|
47
|
+
*,
|
|
48
|
+
settings: Settings,
|
|
49
|
+
client: httpx.AsyncClient,
|
|
50
|
+
) -> ScrapeData | None:
|
|
51
|
+
adapter = adapter_for(request.url)
|
|
52
|
+
if adapter is None:
|
|
53
|
+
return None
|
|
54
|
+
return await adapter.fetch(request, settings=settings, client=client)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
__all__ = ["ADAPTERS", "REDDIT_SETUP", "adapter_for", "fetch_via_adapter"]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""arXiv abstract pages via the public Atom API."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import xml.etree.ElementTree as ET
|
|
6
|
+
from urllib.parse import urlsplit
|
|
7
|
+
|
|
8
|
+
import httpx
|
|
9
|
+
|
|
10
|
+
from dungscraper.config import Settings
|
|
11
|
+
from dungscraper.models import PageMetadata, ScrapeData, ScrapeRequest
|
|
12
|
+
|
|
13
|
+
ATOM = "{http://www.w3.org/2005/Atom}"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def arxiv_id(url: str) -> str | None:
|
|
17
|
+
parts = urlsplit(url)
|
|
18
|
+
host = (parts.hostname or "").lower()
|
|
19
|
+
if host.startswith("www."):
|
|
20
|
+
host = host[4:]
|
|
21
|
+
if host not in {"arxiv.org", "export.arxiv.org"}:
|
|
22
|
+
return None
|
|
23
|
+
segments = [segment for segment in parts.path.split("/") if segment]
|
|
24
|
+
if len(segments) >= 2 and segments[0] in {"abs", "pdf"}:
|
|
25
|
+
return segments[1].removesuffix(".pdf")
|
|
26
|
+
return None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def format_atom(xml_text: str) -> tuple[str, str] | None:
|
|
30
|
+
try:
|
|
31
|
+
root = ET.fromstring(xml_text)
|
|
32
|
+
except ET.ParseError:
|
|
33
|
+
return None
|
|
34
|
+
entry = root.find(f"{ATOM}entry")
|
|
35
|
+
if entry is None:
|
|
36
|
+
return None
|
|
37
|
+
title = " ".join((entry.findtext(f"{ATOM}title") or "").split())
|
|
38
|
+
summary = " ".join((entry.findtext(f"{ATOM}summary") or "").split())
|
|
39
|
+
authors = [
|
|
40
|
+
" ".join((node.findtext(f"{ATOM}name") or "").split())
|
|
41
|
+
for node in entry.findall(f"{ATOM}author")
|
|
42
|
+
]
|
|
43
|
+
published = (entry.findtext(f"{ATOM}published") or "")[:10]
|
|
44
|
+
lines = [f"# {title}", "", f"Authors: {', '.join(authors)}"]
|
|
45
|
+
if published:
|
|
46
|
+
lines.append(f"Published: {published}")
|
|
47
|
+
lines.extend(["", summary])
|
|
48
|
+
return "\n".join(lines).strip(), title
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class ArxivAdapter:
|
|
52
|
+
name = "arxiv"
|
|
53
|
+
|
|
54
|
+
def matches(self, host: str, url: str) -> bool:
|
|
55
|
+
return arxiv_id(url) is not None
|
|
56
|
+
|
|
57
|
+
async def fetch(self, request: ScrapeRequest, *, settings: Settings, client: httpx.AsyncClient) -> ScrapeData | None:
|
|
58
|
+
paper_id = arxiv_id(request.url)
|
|
59
|
+
if paper_id is None or urlsplit(request.url).path.startswith("/pdf/"):
|
|
60
|
+
return None
|
|
61
|
+
response = await client.get(
|
|
62
|
+
"https://export.arxiv.org/api/query",
|
|
63
|
+
params={"id_list": paper_id},
|
|
64
|
+
timeout=20,
|
|
65
|
+
)
|
|
66
|
+
if response.status_code >= 400:
|
|
67
|
+
return None
|
|
68
|
+
formatted = format_atom(response.text)
|
|
69
|
+
if formatted is None:
|
|
70
|
+
return None
|
|
71
|
+
markdown, title = formatted
|
|
72
|
+
return ScrapeData(
|
|
73
|
+
url=request.url,
|
|
74
|
+
markdown=markdown,
|
|
75
|
+
metadata=PageMetadata(title=title, description="arXiv via the public API"),
|
|
76
|
+
render_mode="api",
|
|
77
|
+
status_code=200,
|
|
78
|
+
content_type="application/atom+xml",
|
|
79
|
+
warnings=["arxiv_api"],
|
|
80
|
+
)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""GitHub repository and file reads via the public REST API."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import base64
|
|
6
|
+
from urllib.parse import urlsplit
|
|
7
|
+
|
|
8
|
+
import httpx
|
|
9
|
+
|
|
10
|
+
from dungscraper.config import Settings
|
|
11
|
+
from dungscraper.models import PageMetadata, ScrapeData, ScrapeRequest
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def parse_github(url: str) -> dict | None:
|
|
15
|
+
parts = urlsplit(url)
|
|
16
|
+
host = (parts.hostname or "").lower()
|
|
17
|
+
if host.startswith("www."):
|
|
18
|
+
host = host[4:]
|
|
19
|
+
if host != "github.com":
|
|
20
|
+
return None
|
|
21
|
+
segments = [segment for segment in parts.path.split("/") if segment]
|
|
22
|
+
if len(segments) < 2:
|
|
23
|
+
return None
|
|
24
|
+
owner, repo = segments[0], segments[1]
|
|
25
|
+
if owner in {"topics", "features", "settings", "marketplace"}:
|
|
26
|
+
return None
|
|
27
|
+
path = None
|
|
28
|
+
ref = None
|
|
29
|
+
if len(segments) >= 5 and segments[2] in {"blob", "tree"}:
|
|
30
|
+
ref = segments[3]
|
|
31
|
+
path = "/".join(segments[4:])
|
|
32
|
+
return {"owner": owner, "repo": repo, "ref": ref, "path": path}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class GitHubAdapter:
|
|
36
|
+
name = "github"
|
|
37
|
+
|
|
38
|
+
def matches(self, host: str, url: str) -> bool:
|
|
39
|
+
return host == "github.com" and parse_github(url) is not None
|
|
40
|
+
|
|
41
|
+
async def fetch(self, request: ScrapeRequest, *, settings: Settings, client: httpx.AsyncClient) -> ScrapeData | None:
|
|
42
|
+
parsed = parse_github(request.url)
|
|
43
|
+
if parsed is None:
|
|
44
|
+
return None
|
|
45
|
+
headers = {"Accept": "application/vnd.github+json", "User-Agent": settings.robots_user_agent}
|
|
46
|
+
if settings.github_token:
|
|
47
|
+
headers["Authorization"] = f"Bearer {settings.github_token}"
|
|
48
|
+
owner, repo = parsed["owner"], parsed["repo"]
|
|
49
|
+
repo_response = await client.get(f"https://api.github.com/repos/{owner}/{repo}", headers=headers, timeout=20)
|
|
50
|
+
if repo_response.status_code >= 400:
|
|
51
|
+
return None
|
|
52
|
+
info = repo_response.json()
|
|
53
|
+
if parsed["path"]:
|
|
54
|
+
content_url = f"https://api.github.com/repos/{owner}/{repo}/contents/{parsed['path']}"
|
|
55
|
+
params = {"ref": parsed["ref"]} if parsed["ref"] else None
|
|
56
|
+
file_response = await client.get(content_url, headers=headers, params=params, timeout=20)
|
|
57
|
+
if file_response.status_code >= 400:
|
|
58
|
+
return None
|
|
59
|
+
payload = file_response.json()
|
|
60
|
+
encoded = payload.get("content") or ""
|
|
61
|
+
try:
|
|
62
|
+
text = base64.b64decode(encoded).decode("utf-8", "replace")
|
|
63
|
+
except Exception:
|
|
64
|
+
return None
|
|
65
|
+
language = parsed["path"].rsplit(".", 1)[-1] if "." in parsed["path"] else ""
|
|
66
|
+
markdown = f"# {owner}/{repo}/{parsed['path']}\n\n```{language}\n{text.rstrip()}\n```"
|
|
67
|
+
title = parsed["path"]
|
|
68
|
+
else:
|
|
69
|
+
readme = await client.get(
|
|
70
|
+
f"https://api.github.com/repos/{owner}/{repo}/readme",
|
|
71
|
+
headers={**headers, "Accept": "application/vnd.github.raw"},
|
|
72
|
+
timeout=20,
|
|
73
|
+
)
|
|
74
|
+
body = readme.text if readme.status_code < 400 else ""
|
|
75
|
+
description = info.get("description") or ""
|
|
76
|
+
markdown = f"# {info.get('full_name') or owner + '/' + repo}\n\n{description}\n\n{body}".strip()
|
|
77
|
+
title = info.get("full_name")
|
|
78
|
+
return ScrapeData(
|
|
79
|
+
url=request.url,
|
|
80
|
+
markdown=markdown,
|
|
81
|
+
metadata=PageMetadata(title=title, description=info.get("description")),
|
|
82
|
+
render_mode="api",
|
|
83
|
+
status_code=200,
|
|
84
|
+
content_type="application/json",
|
|
85
|
+
warnings=["github_api"],
|
|
86
|
+
)
|