You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Playwright本地正常,AWS Ubuntu访问tixcraft遇403 Forbidden

解决AWS Ubuntu环境下Playwright访问tixcraft.com出现403 Forbidden的问题

你的问题和安全组配置无关(其他网页能正常访问即可排除),核心是tixcraft的反爬机制识别出了自动化工具或异常环境,以下是具体解决步骤:

1. 模拟真实浏览器的User-Agent与请求头

Playwright默认的UA和请求头容易被反爬规则标记,手动设置主流浏览器的UA及常用请求头:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    # 模拟Chrome最新版本的User-Agent
    user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"
    # 启动浏览器时禁用自动化特征检测
    browser = p.chromium.launch(
        args=["--disable-blink-features=AutomationControlled"]
    )
    # 创建上下文时指定UA、语言头和来源页
    context_tixcraft = browser.new_context(
        user_agent=user_agent,
        viewport={"width": 1920, "height": 1080},  # 模拟桌面端窗口尺寸
        extra_http_headers={
            "Accept-Language": "zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7",
            "Referer": "https://tixcraft.com/"
        }
    )
    page_tixcraft = context_tixcraft.new_page()
    
    print('tixcraft start!')
    # 先访问首页再跳转目标页,模拟真实用户路径
    page_tixcraft.goto("https://tixcraft.com/")
    page_tixcraft.wait_for_timeout(2000)
    page_tixcraft.goto("https://tixcraft.com/activity")
    
    page_tixcraft.wait_for_load_state('load')
    page_tixcraft.wait_for_timeout(1500)
    
    page_content = page_tixcraft.content()
    print(page_content)
    
    browser.close()

2. 禁用自动化特征检测

添加--disable-blink-features=AutomationControlled启动参数,避免Chrome内置的自动化检测机制被网站识别。

3. 模拟真实浏览流程

  • 不要直接访问目标页面,先访问网站首页并停留几秒,再跳转到/activity页面,还原用户正常操作路径。
  • 设置符合桌面端的窗口尺寸,避免使用Playwright默认的小窗口触发异常检测。

4. 排查IP封禁问题

tixcraft可能对云服务商的IP段有封禁策略,可通过以下方式验证:

  • 使用第三方代理IP访问目标页面,测试是否能正常加载。
  • 更换AWS的弹性IP,尝试新的IP地址是否能绕过限制。

5. 额外优化建议

  • 避免高频请求,在请求之间添加随机间隔(比如1-3秒),减少被判定为爬虫的概率。
  • 保持Playwright浏览器版本为最新,旧版本的浏览器特征更容易被反爬规则识别。

内容的提问来源于stack exchange,提问作者akuan10

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 23:50:55