59 Commits
Author SHA1 Message Date
mschoi0411 63a040f601 fix(spiders): interpret asctime Retry-After dates as UTC (#561) 2026-11-14 18:27:06 +02:00
Karim shoair 193bd48776 fix(spider)!: make follow function doesn't inherit any request data from parent
Fixes #558 #587
Avoids the whole bug class.
Closes #559
2026-11-14 18:23:25 +02:00
Lykin 12c855d829 fix(spiders): handle CR record separators in CSV feeds (#551) 2026-11-04 15:56:27 +02:00
Wu Shuwen f0a54ac9b5 fix(spiders): skip malformed links during extraction (#548) 2026-11-03 22:21:08 +02:00
ZHANG YU fc6c7e62c7 fix(spiders): isolate temporary files for concurrent cache writes (#546) 2026-11-03 22:18:16 +02:00
Rayen Mlayeh 49eaff11da fix(spiders): fetch robots.txt once per domain under concurrent requests (#538) 2026-11-02 22:07:57 +02:00
cangen185-sudo 37950a6304 style(spiders): raise error on truncated and invalid gzip in templates (#522) 2026-11-02 20:34:22 +02:00
Suliman Abdulrazzaq 15373320e6 fix(spiders): keep the checkpoint when a crawl ends with an exception (#486) 2026-10-15 20:36:33 +03:00
Suliman Abdulrazzaq 353fc707b2 fix(spiders): let LinkExtractor restrict selectors match the link element itself (#483) 2026-10-15 20:35:16 +03:00
Karim shoair 7183891c31 feat(CrawlSpider): Add crawl strategy with values BFS or DFS 2026-10-13 01:39:11 +03:00
Karim shoair 9cf428038b refactor(rag): Renamed SiteToMarkdownSpider to ContentSpider 2026-10-13 01:08:54 +03:00
Karim shoair 335beb932a test: update tests accordingly 2026-10-08 23:28:12 +03:00
Alex 7831c19eb3 fix(spiders): preserve falsy JSON bodies in request fingerprints (#480) 2026-10-08 02:10:10 +03:00
Yuval DinodiaandKarim shoair 1ac8e52fb1 fix: stop response.follow() inheriting the method, params and body (#462)
* fix: stop response.follow() inheriting the method, params and body

* fix: drop inherited Content-Length in response.follow()

---------

Co-authored-by: Karim shoair <D4Vinci@users.noreply.github.com>
2026-10-08 02:06:50 +03:00
Yiğit ERDOĞAN 06ae92f17f fix(spiders): pass stealthy_headers to the session instead of curl_cffi (#475)
The public FetcherSession methods pop `stealthy_headers` and hand it to
`_make_request` as `stealth`. SessionManager.fetch forwarded the request
kwargs untouched, so `Request(url, stealthy_headers=False)` reached
curl_cffi as an unknown argument, and the request failed with a TypeError
that the default `on_error` swallows. Map it the same way here.
2026-10-07 01:37:09 +03:00
Sarwadnya Mahajan 4b97bfe4a3 fix: make request fingerprint independent of header order (#466)
- Sort processed headers tuple when generating request fingerprint

- Add a regression test in tests/spiders/test_request.py

- Fixes #465
2026-10-07 01:25:32 +03:00
Suliman Abdulrazzaq 8d600c4edd fix(spiders): route sitemap URLs to parse() instead of the sitemap parser (#458)
When rules() is empty, or a matching CrawlRule has no callback, SitemapSpider followed each URL without a callback, so Response.follow() inherited _parse_sitemap from the sitemap request. It then parsed every page as a sitemap, and parse() was never called. The spider's parse() is now passed explicitly, as the docs describe.
2026-09-25 02:55:53 +03:00
diegobravtraps-oss 80332cf3a7 test: make checkpoint and CSV tests portable to Windows (#457)
Compare checkpoint paths as Path objects instead of POSIX string literals,
and read CSV output with read_text() so no file handle stays open when the
TemporaryDirectory is cleaned up (Windows refuses to delete open files).
2026-09-25 02:44:58 +03:00
Suliman AbdulrazzaqandKarim shoair 6ee33221a2 fix(spiders): ignore a leading byte-order mark in robots.txt and CSV feeds (#453)
- Strip a leading BOM before handing a robots.txt body to protego in
  RobotsTxtManager and SitemapSpider. Left in place, it glues onto the first
  directive, so a file starting with `User-agent: *` loses that whole group
  (Disallow, Crawl-delay) and one starting with `Sitemap:` loses the sitemap.
- Strip it from CSV feed text too, so the first column is not keyed as
  "\ufefftitle" for spreadsheet exports that start with a BOM.
- Added regression tests for all three paths.

Co-authored-by: Karim shoair <D4Vinci@users.noreply.github.com>
2026-09-19 19:15:36 +03:00
Suliman AbdulrazzaqandKarim shoair f7b3137986 fix(spiders): return no links when a LinkExtractor restriction matches nothing (#452)
`extract()` fell back to the whole page whenever `scopes` was empty, which
also happens when `restrict_css`/`restrict_xpath` are set but match nothing
on the page. A rule scoped to e.g. `.pagination` then returned every link on
a page without that block (such as the last page), so `CrawlSpider` followed
navigation, footer and external links the rule was meant to exclude.

- Only fall back to the whole page when no restriction is configured.
- Added a regression test for CSS, XPath, and combined restrictions.

Co-authored-by: Karim shoair <D4Vinci@users.noreply.github.com>
2026-09-19 19:00:37 +03:00
Prateek RawatandKarim shoair e0be0c527c fix: robots.txt fetch failures cached as allow-all (#443)
* fix: robots.txt fetch failures cached as allow-all

* fix: cache deny-all result after robots.txt fetch failure

Per maintainer feedback on PR #443: instead of returning an
uncached deny-all parser directly from the 5xx/exception branches,
set content to "User-agent: *\nDisallow: /" and let execution fall
through to the existing parse/cache logic. A fetch failure is now
cached the same way as any other outcome, so queued pages on the
same domain reuse the deny-all result instead of re-fetching
robots.txt for each one.

Also trimmed the inline rationale comments in _get_parser down to
the two log.warning lines.

Updated tests in TestFailureCaching to assert caching instead of
no-caching: test_5xx_response_is_cached and
test_fetch_exception_is_cached now expect a single fetch call
across two can_fetch checks. Dropped test_recovers_once_fetch_succeeds
since a failure result no longer retries on the next call.

---------

Co-authored-by: Karim shoair <D4Vinci@users.noreply.github.com>
2026-09-19 17:39:35 +03:00
Kuang-xianxinandKuang-xianxin ce294063e9 fix(spiders): cache responses only after blocked-response checks (#446)
* fix(spiders): avoid replaying blocked responses from development cache

* fix(spiders): leave development cache replay unchanged

---------

Co-authored-by: Kuang-xianxin <243476082+Kuang-xianxin@users.noreply.github.com>
2026-09-18 12:35:22 +03:00
Yuval DinodiaandKarim shoair 2beadcf7af fix(spiders): include params in the request fingerprint (#448)
* fix: include params in the request fingerprint so paginated requests are not deduplicated away

* fix: use curl_cffi's update_url_params so the fingerprint follows the engine's URL rules for fragments, existing keys, and list/bool values

---------

Co-authored-by: Karim shoair <D4Vinci@users.noreply.github.com>
2026-09-18 02:59:16 +03:00
Александр М. 4702b5aa9e fix(spiders): skip non-element nodes in sitemap XML instead of crashing on comments (#450) 2026-09-18 01:32:00 +03:00
Karim shoair 5edd203076 feat(browsers): Include open Shadow DOM content in the response HTML.
Solves #440
2026-09-13 23:30:08 +03:00
Yiğit ERDOĞAN 63cdc99cfd fix(spiders): keep the request meta on cached responses (#419) 2026-08-23 21:58:21 +03:00
Karim shoair 6ca35d0448 feat(spiders): Adding easy interface for building RAG systems 2026-08-23 16:26:15 +03:00
Karim shoair 9bbd7c8b25 feat(spiders): Add XML/CSV feed templates + docs 2026-08-09 20:44:12 +03:00
Karim shoair 0a7fec8f86 feat(spiders): Add exporters to CSV/XML 2026-07-26 23:13:35 +03:00
Karim shoair ca51962421 feat(spiders): Auto throttle based on website speed/protection 2026-07-26 22:54:36 +03:00
Amit Vijapur 3ed4fde93a fix(spiders): preserve cookies for browser-engine responses in cache (#376)
ResponseCacheManager.put() only recognized the flat `dict` shape that
static-engine responses use for `Response.cookies`. Browser engines
(Playwright) populate cookies as a `tuple` of full cookie dicts, so the
isinstance(dict) guard fell through to the `else {}` branch and silently
discarded every cookie before it ever reached the cache file. Replaying a
cached browser-engine response then rebuilt it with cookies={}.

Preserve whichever shape the cookies are in instead of collapsing anything
non-dict to {}: serialize a tuple as a JSON array and a dict as a JSON
object, then restore the tuple shape on read since JSON arrays deserialize
back as `list`.

Add regression tests covering both the browser-engine (tuple) and
static-engine (dict) cookie round-trip through put()/get().
2026-07-21 00:38:48 +08:00
Karim shoair 4022dac086 feat: add a template for Shopify websites 2026-07-12 18:44:11 +03:00
Karim shoair 13eb6b0971 Merge branch 'dev' into fix-linkextractor-compound-extensions 2026-06-30 01:08:55 +03:00
renbkna 0d35a3f94d fix: honor compound link deny extensions 2026-06-26 10:52:38 +02:00
Karim shoair 82015b3d1f Merge branch 'dev' into fix/checkpoint-in-flight-requests 2026-06-26 11:49:32 +03:00
yetval 95687a5e37 fix: track in-flight requests by queue counter so duplicate instances are not collapsed 2026-06-23 20:31:28 +00:00
yetval d1082bd2d8 fix: keep in-flight requests in checkpoints so resume does not lose them 2026-06-22 11:27:41 -04:00
Disaster-Terminator 139ba13af6 test: align robots request-rate expectation 2026-06-17 21:09:09 +08:00
Ahmed Elshahat f0db3d7d14 fix(spiders): use os.replace for atomic checkpoint/cache writes on Windows
CheckpointManager.save() and ResponseCacheManager.put() write to a temp
file and then move it into place with Path.rename(). On Windows, os.rename
cannot overwrite an existing destination and raises FileExistsError
(WinError 183), so every write after the first one fails: checkpoint
saving raises and breaks resume, while the development response cache
swallows the error and keeps returning the stale entry.

Path.replace() (os.replace) overwrites the destination atomically on every
platform and behaves identically to rename() on POSIX, so this is a no-op
on Linux and macOS and only fixes the broken overwrite on Windows.

Add a regression test for the cache overwrite path; the checkpoint
overwrite is already covered by test_multiple_saves_overwrite.
2026-06-07 04:24:12 +03:00
Karim shoair 34651abc6b tests: remove old code and update the rest 2026-05-11 03:30:59 +03:00
Karim shoair 8a8b2d14ba test: add tests accordingly 2026-05-11 02:33:43 +03:00
yetval 334b0f5538 fix: str(value) 2026-04-30 09:52:34 -04:00
yetval a5a5652996 test: add request fingerprint regressions 2026-04-26 16:31:58 -04:00
Karim shoair d1baf1fc46 feat(spiders): add a development mode 2026-04-07 04:08:54 +02:00
d 🔹 9950dde724 test: align force-stop regression stubs with dev branch 2026-04-05 19:13:19 +00:00
voidborne-d eaa0e8cae6 fix: save checkpoint before cancel_scope.cancel() on force-stop to prevent data loss
On force-stop (second Ctrl+C), cancel_scope.cancel() was called BEFORE
_save_checkpoint(). Since cancel_scope.cancel() causes all subsequent
awaits within the scope to raise Cancelled, the checkpoint write was
silently aborted:

1. _save_checkpoint() uses anyio.open_file + rename — both are await
   checkpoints that get cancelled immediately
2. self.paused never gets set to True (code after the aborted save)
3. The finally block sees 'not self.paused' and calls cleanup() which
   DELETES the previous checkpoint file

Result: a user who ran a long crawl, pressed Ctrl+C twice to force-stop,
loses their entire checkpoint irrecoverably. The old checkpoint (from
periodic saves or a previous graceful pause) is deleted, and the new
one was never written.

Fix: move the cancel_scope.cancel() call AFTER the checkpoint save.
The save completes normally, self.paused is set to True, and only then
does the scope get cancelled to abort in-flight tasks. The finally
block correctly sees paused=True and skips cleanup.

Adds 6 regression tests covering:
- Force-stop checkpoint preservation (core regression)
- Graceful pause still works
- Force-stop checkpoint is loadable
- Normal completion cleanup still works
- Force-stop without checkpoint system
- Existing checkpoint not deleted on force-stop
2026-04-05 19:11:58 +00:00
Karim shoair afaf68e7d5 fix(spider robots): removing dead code 2026-04-05 02:32:33 +02:00
Abdullah a86e9709ea feat(spiders): pre-warm robots.txt cache before crawl loop starts
Previously robots.txt was fetched lazily on the first request per
domain, causing early concurrent requests to each stall waiting for
the same network fetch. The cache is now warmed before the crawl loop
starts, making all subsequent robots.txt lookups a local read.

- RobotsTxtManager gains a prefetch(urls, sid) method that fetches all domains concurrently via a task group
- CrawlerEngine._prefetch_robots_txt() is called after on_start():
  uses allowed_domains if configured, otherwise falls back to unique
  domains extracted from start_urls
- Mid-crawl domain discovery (not covered by prefetch) still fetches
  lazily; two concurrent callbacks on the same new domain can each
  trigger a fetch — accepted tradeoff, documented in _get_domain_delay

Files: scrapling/spiders/robotstxt.py, scrapling/spiders/engine.py, tests/spiders/test_engine.py
2026-04-04 03:00:15 +02:00
Abdullah e2b293f41c refactor(spiders): simplify robots.txt cache to domain-only key
robots.txt is a domain-level document and does not vary by session.

Keying the cache by (domain, sid) was both wasteful and incorrect —
it caused redundant fetches when the same domain was accessed by different sessions.

- Cache is now keyed by domain string only; all sessions share one entry
- Removed asyncio.Event inflight-deduplication mechanism (superseded by the prefetch approach added in the next commit)
- clear_cache() loses the `sid` parameter (breaking change); clearing a domain now evicts the single shared entry for all sessions
- Updated tests to reflect shared-cache semantics

Files: scrapling/spiders/robotstxt.py, tests/spiders/test_robotstxt.py
2026-04-04 03:00:15 +02:00
Abdullah 132f33c846 test(spiders): add comprehensive test suite for robots.txt compliance 2026-04-03 15:08:34 +02:00