Skip to content

Commit 2c53c0f

Browse files
authored
Merge pull request #2054 from harehare/feat/crawler-retry-auth
✨ feat(mq-crawler): add retry/backoff and auth/header/cookie support
2 parents 7780ee5 + e42fda7 commit 2c53c0f

7 files changed

Lines changed: 517 additions & 53 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/mq-crawler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ repository = "https://github.com/harehare/mq"
1212
version = "0.6.5"
1313

1414
[dependencies]
15+
base64 = {workspace = true}
1516
chromiumoxide = {workspace = true}
1617
clap = {workspace = true, features = ["derive"]}
1718
crossbeam = {workspace = true}

crates/mq-crawler/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Make web scraping and content extraction effortless with intelligent Markdown co
2727
- **WebDriver Support**: Use Selenium WebDriver for browser-based crawling
2828
- **Domain Filtering**: Restrict crawling to specific domains
2929
- **Sitemap Ingestion**: Seed the crawl frontier from a `sitemap.xml` (or sitemap index) up front
30+
- **Retry with Backoff**: Automatically retries failed requests (network errors, 429, 5xx) with exponential backoff
31+
- **Custom Headers & Cookies**: Send custom HTTP headers and cookies with every request
32+
- **Authentication**: Basic and bearer-token authentication for protected sites
3033

3134
## Installation
3235

@@ -123,6 +126,37 @@ mq-crawl --sitemap https://example.com/sitemap.xml https://example.com
123126
mq-crawl --depth 0 --sitemap https://example.com/sitemap.xml https://example.com
124127
```
125128

129+
### Retry & Backoff
130+
131+
```bash
132+
# Retry failed requests (network errors, 429, 5xx) up to 5 times,
133+
# starting at a 1s delay and doubling up to a 30s cap
134+
mq-crawl --max-retries 5 --retry-initial-backoff 1 --retry-max-backoff 30 https://example.com
135+
136+
# Disable retries entirely
137+
mq-crawl --max-retries 0 https://example.com
138+
```
139+
140+
### Custom Headers, Cookies & Authentication
141+
142+
```bash
143+
# Send a custom header with every request
144+
mq-crawl --header "X-Api-Key: secret" https://example.com
145+
146+
# Send one or more cookies
147+
mq-crawl --cookie "session=abc123" --cookie "theme=dark" https://example.com
148+
149+
# HTTP Basic authentication
150+
mq-crawl --basic-auth alice:s3cret https://example.com
151+
152+
# Bearer token authentication
153+
mq-crawl --bearer-token eyJhbGciOi... https://example.com
154+
```
155+
156+
> **Note**: `--header`, `--cookie`, `--basic-auth`, and `--bearer-token` apply
157+
> only to standard (non-browser) crawling; they are ignored with `--headless`
158+
> or `-U/--webdriver-url`.
159+
126160
### Custom Robots.txt
127161

128162
```bash
@@ -240,6 +274,22 @@ Options:
240274
Output format: text or json [default: text]
241275
--sitemap <SITEMAP_URL>
242276
URL of a sitemap.xml (or sitemap index) to enumerate additional seed URLs from
277+
--max-retries <MAX_RETRIES>
278+
Maximum retry attempts for failed requests (network errors, 429, 5xx) [default: 3]
279+
--retry-initial-backoff <RETRY_INITIAL_BACKOFF>
280+
Delay in seconds before the first retry [default: 0.5]
281+
--retry-max-backoff <RETRY_MAX_BACKOFF>
282+
Maximum delay in seconds between retries [default: 10]
283+
--retry-backoff-multiplier <RETRY_BACKOFF_MULTIPLIER>
284+
Multiplier applied to the retry delay after each failed attempt [default: 2]
285+
--header <KEY: VALUE>
286+
Custom HTTP header to send with every request (repeatable); non-browser crawling only
287+
--cookie <NAME=VALUE>
288+
Cookie to send with every request (repeatable); non-browser crawling only
289+
--basic-auth <USER:PASS>
290+
HTTP Basic authentication credentials; non-browser crawling only
291+
--bearer-token <TOKEN>
292+
Bearer token for Authorization header; non-browser crawling only
243293
--extract-scripts-as-code-blocks
244294
Extract <script> tags as code blocks in Markdown
245295
--generate-front-matter

0 commit comments

Comments
 (0)