2.0 KiB
2.0 KiB
Engineering & Scraping Guidelines
1. Git Commit & Repository Hygiene
- Conventional Commits: Write clear, concise commit messages prefixed with standard types (e.g.,
feat:,fix:,refactor:,docs:). - Exclude Transient Artifacts: Never stage or commit generated debug files (e.g.,
src/*.html,src/*.png, large logs) to version control. Always maintain.gitignoreto keep git packs lean and prevent remote unpacker errors on Gitea/GitHub.
2. Web Scraping & DOM Inspection Strategy
- Rendered DOM Dumping for Debugging: When debugging extraction failures on dynamic or anti-bot protected pages:
- Capture the post-render HTML via
await page.content()and save it tosrc/hotel-debug.html. - Capture a synchronized screenshot (
src/hotel-debug.png). - Inspect the raw rendered DOM to verify if the page was served as standard SSR, an A/B test SPA variant, or intercepted by a challenge (e.g. AWS WAF).
- Capture the post-render HTML via
- Multi-Tier Extraction Hierarchy: Always implement fallbacks in this order:
- Deep JSON-LD Parsing: Traverse all
<script type="application/ld+json">tags, including@grapharrays and varied accommodation schemas (Hotel,Resort,Apartment,Hostel,LodgingBusiness, etc.). - DOM Selectors: Fallback to standard test IDs, classes, and element hierarchy (
data-testid, header titles, score components). - Meta Tags: Fallback to OpenGraph and Twitter meta tags (
og:title,og:image,og:description). - URL Slug Extraction: As an ultimate safety net, derive clean human-readable names from the URL path if the HTML body was obstructed.
- Deep JSON-LD Parsing: Traverse all
- Anti-Bot & WAF Handling:
- Sanitize input URLs by stripping transient tokens (
chal_t,force_referer, session IDs). - Emulate full browser properties (
window.chrome,navigator.plugins,navigator.languages). - Actively detect WAF challenge interstitial pages and wait for client-side JavaScript token computation and automatic redirection before evaluating the DOM.
- Sanitize input URLs by stripping transient tokens (