协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
agentcore-browser-web-scraping【开发与工程】Build production web scraping on Bedrock AgentCore Browser — connect Playwright over signed CDP WebSocket, drive extraction with an LLM agent over fixed tool primitives (navigate, scroll, extract-by-selector, screenshot), reuse login state via Browser Profiles with a DCV live-view login flow, detect login walls without false positives, and route thro…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Amazon Bedrock AgentCore Browser gives you a managed cloud Chromium — no crawler fleet, no resident containers, per-session billing, natural isolation. This skill captures a production scraping architecture built on it: an LLM agent decides what to do on the page, but only through fixed code primitives it can parameterize, never arbitrary scripts. Login state lives in Browser Profiles that users populate once through a live-view session, so credentials never transit the conversation.
Collector (Python, worker thread)
├─ browser_session(region, profile_configuration=..., proxy_configuration=...)
│ └─ StartBrowserSession → generate_ws_headers() (SigV4)
│ └─ playwright chromium.connect_over_cdp(ws_url, headers)
└─ Strands Agent (LLM) with 6 fixed tools:
navigate / scroll_to_bottom / click_load_more /
get_page_text / screenshot / extract_by_selector
Reference this skill when:
Not for: general AgentCore Browser service overview or session APIs —
see the aws-agentic-ai skill's Browser service docs for that.
Connect Playwright to the managed browser over a SigV4-signed CDP WebSocket, then let an LLM agent drive a bounded tool loop. Key decisions:
extract_by_selector: a constant JS extraction template evaluated with
the model's CSS selectors passed as data arguments — zero string
concatenation, zero eval. Preserves item boundaries and attributes that a
flat innerText dump loses.screenshot (downscaled JPEG returned as an image tool-result) lets
the model see the page and distinguish "genuinely empty" from login
wall / CAPTCHA / cookie banner before declaring failure.document.body.scrollHeight is 0 on
flex layouts (YouTube) — scroll document.scrollingElement instead, and
also iterate inner overflow panels; comments often live in an overlay
that window scrolling never touches.navigate tool on every call, so the model can't pivot mid-session.See references/session-and-extraction.md
— includes IAM specifics (the browser/ vs browser-custom/ ARN pitfall,
InvokeModelWithResponseStream), the asyncio × sync-Playwright worker-thread
requirement, and the error-code taxonomy.
Users log in once inside the cloud browser via a DCV live-view page; the
session's cookies/tokens are saved to an AgentCore Browser Profile and reused
by every later scrape (profile_configuration={"profileIdentifier": ...}).
Credentials never appear in the conversation or your database.
Flow: mint a one-time URL token → start_browser_session with the profile →
presign the live-view stream endpoint (SigV4 query auth) → embed the DCV
Web Client → on completion save_browser_session_profile then
stop_browser_session (that order — save requires a live session).
The subtle part is login-wall detection without false positives. Hitting a wall does not mean the stored login is dead (a login can stay valid across days and multiple egress IPs while an overlay still blocks anonymous views). Use three layers: a pre-flight gate for known login-walled hosts, an in-scrape sentinel from the model, and an active probe that replays the session's cookies against a login-sensitive endpoint to ask the server directly — only a definitive INVALID expires the stored profile.
See references/login-profiles-and-liveview.md
— includes profile-name constraints and idempotent creation, DCV embed
gotchas (WebCodecs, absolute baseUrl), the Google SSO third-party-cookie
fix via Chromium enterprisePolicies, and the parked-task auto-resume
pattern.
start_browser_session accepts a proxyConfiguration with an
externalProxy (server, port, credentials by Secrets Manager ARN only
— never inline). Fall back gracefully to the default egress when
unconfigured.time_confidence="unknown". Never drop, never null.See references/proxy-and-data-normalization.md.
Adoption checklist:
bedrock-agentcore and a boto3 recent enough to know
profileConfiguration / the bedrock-agentcore service (Lambda's bundled
boto3 is too old — bundle your own).bedrock:InvokeModel and InvokeModelWithResponseStream
to the agent's model, and write Browser session ARNs in both browser/
and browser-custom/ forms.[],
or typed sentinels like LOGIN_NEEDED: <host> / BLOCKED: <reason>) and
parse defensively.enterprisePolicies to login sessions and scrape
sessions — SSO cookies saved under one policy break under another.