Understand the advantages of scrapy-splash over direct Splash HTTP API calls
masterWhile you can interact with Splash by sending POST requests to render.html manually, scrapy-splash provides several critical improvements:
- Reduces Boilerplate: Automates the construction of JSON bodies and headers.
- Correct URL Handling: Fixes
response.urlto be the target page URL instead of the Splash server URL. The original URL is available viaresponse.real_url. - Improved Scrapy Integration:
- Handles
response.statusandresponse.headerstransparently. - Ensures
CONCURRENT_REQUESTS_PER_DOMAINandDOWNLOAD_DELAYwork correctly by mapping requests to their actual target domains. - Fixes duplication filtering (dupefilter) to correctly canonicalize URLs sent in JSON bodies.
- Handles
- Error Debugging:
SplashMiddlewareautomatically logs the content of HTTP 400 (Bad Request) responses from Splash to help debugging. This can be disabled via theSPLASH_LOG_400 = Falsesetting. - Cookie & State Management: Simplifies cookie handling which is otherwise difficult to implement manually with Splash.
- Efficiency: Provides optimized storage for large, static Splash arguments (like
lua_source) in Scrapy disk request queues and supports Splash 2.1+ caching viasave_argsandload_args.