Skip to content

feat(spiders): LinkExtractor, CrawlSpider/CrawlRule, SitemapSpider#71

Merged
Liohtml merged 2 commits into
masterfrom
claude/upstream-scrapling-changes-1sub94-pr3
Jul 11, 2026
Merged

feat(spiders): LinkExtractor, CrawlSpider/CrawlRule, SitemapSpider#71
Liohtml merged 2 commits into
masterfrom
claude/upstream-scrapling-changes-1sub94-pr3

Conversation

@Liohtml

@Liohtml Liohtml commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Summary

Upstream sync (3/4). Ports the upstream Scrapling v0.4.8 spider features (18e9121, f093d0c, f7da157) plus the compound-extension fix (0d35a3f):

  • LinkExtractor (src/spiders/links.rs): regex allow/deny, domain allow/deny with subdomain matching, restrict_css scoping, configurable tags/attrs, URL canonicalization (sorted query params, fragment drop), whitespace stripping, scheme filtering, a process hook, and the default IGNORED_EXTENSIONS deny list. Compound extensions like archive.tar.gz match via suffix chains.
  • CrawlRule + CrawlSpider (src/spiders/templates/crawler.rs): declarative link-following rules with priority override and a process_request hook.
  • SitemapSpider (src/spiders/templates/sitemap.rs): seeds crawls from sitemap or robots.txt URLs (Sitemap: directives), recurses into <sitemapindex> children (filtered by sitemap_follow), dispatches <urlset> entries through the rules (first match wins), optional alternate-language links.

Port adaptations (Python → Rust)

  • The Python originals dispatch per-request callbacks; the Rust Spider trait routes everything through parse(). Templates are therefore concrete builder-configured spiders: item extraction is a parse_item closure, and SitemapSpider recognizes sitemap documents by inspecting the response (robots.txt path, <urlset>/<sitemapindex> roots).
  • Transport-level gzip (Content-Encoding: gzip) is decompressed by reqwest; raw .xml.gz files are documented as unsupported since response bodies are stored as text.
  • restrict_xpath is omitted (the parser is CSS-based).

Tests

21 new tests: 15 LinkExtractor unit tests (including the tar.gz compound-extension regression) and 6 template tests, four of which run the real crawl engine end-to-end via the dev-mode response cache (CrawlSpider rule following, sitemap robots.txt → index → urlset → content-page chain, sitemap_follow filtering, no-rules follow-all). Full suite green locally: 259 passed (cargo test, cargo clippy --all-targets -- -D warnings, cargo fmt --check).

🤖 Generated with Claude Code

https://claude.ai/code/session_01KDFsMaKk764vogjUW3nqpk


Generated by Claude Code

Port the upstream Scrapling v0.4.8 spider features:

- LinkExtractor (spiders/links.rs): regex allow/deny filters, domain
  allow/deny with subdomain matching, restrict_css scoping, configurable
  tags/attrs, URL canonicalization (sorted query params, fragment drop),
  HTML5 whitespace stripping, scheme filtering, a process hook, and the
  default IGNORED_EXTENSIONS deny list. Compound extensions like tar.gz
  are matched via suffix chains (upstream fix 0d35a3f).

- CrawlRule + CrawlSpider (templates/crawler.rs): declarative
  link-following rules with priority override and a process_request
  hook. The Python original dispatches to per-rule callbacks; this port
  routes everything through parse(), so item extraction is a
  spider-level parse_item closure.

- SitemapSpider (templates/sitemap.rs): seeds crawls from sitemap or
  robots.txt URLs (Sitemap: directives), recurses into sitemapindex
  children (filtered by sitemap_follow), dispatches urlset entries
  through the rules (first match wins), optional alternate-language
  links. Transport-level gzip is handled by the HTTP client; raw .xml.gz
  files are documented as unsupported since bodies are stored as text.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KDFsMaKk764vogjUW3nqpk
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Liohtml, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 10 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a8290654-c82c-4242-9d62-eb86a3dc2d28

📥 Commits

Reviewing files that changed from the base of the PR and between df09f89 and 6d3d8c2.

📒 Files selected for processing (8)
  • src/lib.rs
  • src/spiders/links.rs
  • src/spiders/mod.rs
  • src/spiders/templates/crawler.rs
  • src/spiders/templates/mod.rs
  • src/spiders/templates/sitemap.rs
  • tests/spiders_links.rs
  • tests/spiders_templates.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/upstream-scrapling-changes-1sub94-pr3

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

- Sitemap parsing now uses descendant traversal with dedup instead of
  direct-children walks: html5ever treats self-closing unknown elements
  (<xhtml:link/>) as open tags and nests what follows inside them, so a
  <loc> after an alternate link (or a second alternate) was silently
  lost.
- Relative URLs from robots.txt Sitemap directives, sitemapindex
  children, and urlset locs are resolved against the response URL,
  mirroring upstream's response.follow(); previously they were dropped
  by the scheme filter or dispatched as unfetchable literals.
- looks_like_sitemap now requires <urlset>/<sitemapindex> as the root
  element (after BOM/prolog/comments) instead of scanning 4 KB of body,
  so HTML content pages mentioning "<urlset" in a script are no longer
  misclassified and their items dropped.
- robots.txt parsing strips inline '#' comments.
- canonicalize_url sorts raw query segments instead of decoded pairs:
  non-UTF-8 percent-escapes (%FF) survive, and empty queries (/p?)
  normalize away so they dedupe with /p.
- LinkExtractor::extract queries one selector list per scope so results
  come back in true document order across tags.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KDFsMaKk764vogjUW3nqpk
@Liohtml Liohtml merged commit 3d2dbcf into master Jul 11, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants