使用Splash渲染sephora.com.au/brands页面失败,求解决方案
解决Splash渲染Sephora澳洲品牌页时的JavaScript未启用提示问题
以下是可行的解决办法:
确认并强制开启Splash的JavaScript支持
Splash默认启用JS,但部分场景下可能被意外禁用。可以在请求脚本中显式设置启用:function main(splash, args) splash.js_enabled = true -- 强制开启JS assert(splash:go(args.url)) assert(splash:wait(2)) -- 等待页面加载完成 return splash:html() end如果用HTTP API直接调用,可添加参数
js_enabled=1。设置真实浏览器的User-Agent
网站可能通过UA识别非真实浏览器,导致JS检测逻辑触发。在脚本中添加真实浏览器的UA:function main(splash, args) splash.js_enabled = true splash:set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36") assert(splash:go(args.url)) assert(splash:wait(3)) return splash:html() end补充浏览器请求头与特性模拟
模拟真实浏览器的请求头和插件状态,避免被反爬机制拦截:function main(splash, args) splash.js_enabled = true splash.plugins_enabled = true splash:set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36") splash:set_custom_headers({ ["Accept-Language"] = "en-US,en;q=0.9", ["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" }) assert(splash:go(args.url)) assert(splash:wait(3)) return splash:html() end检查Splash服务的启动配置
确保Splash启动时没有禁用JS的参数,部分环境下可能需要在启动命令中添加--enable-javascript(如果Splash版本支持该参数),然后重启服务。
内容的提问来源于stack exchange,提问作者Sara Zaky
相关产品推荐
相关产品推荐

