Splash无法正常渲染galaxus.ch站点搜索页内容问题求助
问题根因
galaxus.ch近期更新了反爬检测规则,可识别Splash默认的无头浏览器特征、旧版本请求标识,之前的脚本配置特征和真实浏览器差异过大,因此被拦截无内容返回。
修复后脚本
function main(splash, args) -- 替换为较新版本Chrome UA,规避旧版本浏览器特征拦截 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.private_mode_enabled = false splash.js_enabled = true -- 补全真实浏览器常规请求头,消除请求特征差异 splash:set_custom_headers({ ["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", ["Accept-Language"] = "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3", ["Accept-Encoding"] = "gzip, deflate, br", ["Connection"] = "keep-alive", ["Upgrade-Insecure-Requests"] = "1" }) -- 清除历史Cookie,避免之前的异常访问被站点标记 splash:clear_cookies() assert(splash:go(args.url)) -- 随机等待时长,同时等待站点反爬前置校验逻辑执行完成 assert(splash:wait(math.random(3,7))) -- 模拟真实用户滚动操作,规避无交互爬虫检测 splash:scroll_position = {y=math.random(100,300)} assert(splash:wait(1)) splash:set_viewport_full() return { png = splash:png(), html = splash:html() } end
补充说明
- 脚本里的UA版本可随Chrome正式版更新同步替换,避免版本过低被拦截
- 如果修改脚本后依然无法访问,可在启动Splash时追加
--disable-web-security参数关闭同源策略校验,若为IP被临时封禁可搭配代理IP使用
内容的提问来源于stack exchange,提问作者Raisul Islam
相关产品推荐
相关产品推荐

