求助:Hyatt反爬更新致Selenium-Profiles返回字段为null的解决办法
Hyatt网站积分房接口爬取问题:
lowestPointValue字段返回null 我使用Selenium-Profiles抓取Hyatt网站的积分房可用情况,目标接口为:https://www.hyatt.com/shop/service/rooms/roomrates/dpsas?spiritCode=dpsas&rooms=1&adults=2&checkinDate=2024-01-05&checkoutDate=2024-01-07&kids=0
此前工具运行顺畅,但网站更新反爬机制后,Selenium-Profiles加载页面返回的lowestPointValue字段为null(截图:Selenium-Profiles返回结果),而手动加载页面时该字段值为40000(截图:手动加载返回结果)。我已尝试更新代理配置、调整各类参数、切换VPN/代理,均无效果。
以下是我的Selenium-Profile初始化代码:
profile = json.loads(os.getenv('SELENIUM_PROFILE_3')) profile["proxy"] = { "proxy": super_proxy_url } options = ChromeOptions() options.add_argument("--headless") options.add_argument("--no-sandbox") options.add_argument("--disable-dev-shm-usage") driver = Chrome(profile=profile, options=options,uc_driver=False,injector_options=True, seleniumwire_options=True) driver.execute_cdp_cmd('Runtime.disable',{}) injector = driver.profiles.injector
可行解决建议
- 移除
Runtime.disable命令:这条CDP操作会让网站检测到异常行为,正常浏览器不会禁用Runtime模块,直接删除driver.execute_cdp_cmd('Runtime.disable',{})后测试。 - 调整无头模式配置:先关闭
--headless参数验证非无头模式是否能正常获取字段;若正常,改用Chrome 112+支持的新无头模式--headless=new,同时添加--window-size=1920,1080模拟真实窗口尺寸。 - 启用undetected-chromedriver:将
uc_driver=True,利用undetected-chromedriver的成熟反爬规避能力,替代基础的Selenium配置。 - 模拟真实访问流程:先导航到Hyatt首页,等待页面加载完成(可使用显式等待
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, 'body')))),再请求目标接口,模拟用户正常浏览的延迟和Cookie加载过程。 - 校验代理匿名性:确保使用的是高匿代理,避免代理泄露真实IP或携带异常请求头,可通过请求IP检测站点验证代理的透明性。
- 对齐真实请求头:通过浏览器开发者工具复制手动访问时的完整请求头(包括User-Agent、Accept、Accept-Language等),在Selenium-Profiles或seleniumwire中配置完全一致的请求头参数。
内容的提问来源于stack exchange,提问作者burnmypoints
相关产品推荐
相关产品推荐

