feat(spiders): LinkExtractor, CrawlSpider/CrawlRule, SitemapSpider#71
Conversation
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
|
Warning Review limit reached
Next review available in: 10 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
- 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
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_cssscoping, configurable tags/attrs, URL canonicalization (sorted query params, fragment drop), whitespace stripping, scheme filtering, aprocesshook, and the defaultIGNORED_EXTENSIONSdeny list. Compound extensions likearchive.tar.gzmatch via suffix chains.CrawlRule+CrawlSpider(src/spiders/templates/crawler.rs): declarative link-following rules with priority override and aprocess_requesthook.SitemapSpider(src/spiders/templates/sitemap.rs): seeds crawls from sitemap or robots.txt URLs (Sitemap:directives), recurses into<sitemapindex>children (filtered bysitemap_follow), dispatches<urlset>entries through the rules (first match wins), optional alternate-language links.Port adaptations (Python → Rust)
Spidertrait routes everything throughparse(). Templates are therefore concrete builder-configured spiders: item extraction is aparse_itemclosure, andSitemapSpiderrecognizes sitemap documents by inspecting the response (robots.txt path,<urlset>/<sitemapindex>roots).Content-Encoding: gzip) is decompressed by reqwest; raw.xml.gzfiles are documented as unsupported since response bodies are stored as text.restrict_xpathis omitted (the parser is CSS-based).Tests
21 new tests: 15
LinkExtractorunit tests (including thetar.gzcompound-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_followfiltering, 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