@@ -40,20 +40,27 @@ async def main() -> None:
4040
4141 try :
4242 target_url = "https://news.ycombinator.com"
43- await page .goto (target_url , wait_until = "networkidle" )
4443 await session .navigate (url = target_url )
44+ await page .goto (target_url , wait_until = "networkidle" )
45+
46+ print ("🎯 Stagehand already navigated to Hacker News; Playwright now drives that page." )
47+
48+ # Click the first story's comments link with Playwright.
49+ comments_selector = "tr.athing:first-of-type + tr .subline > a[href^='item?id=']:nth-last-of-type(1)"
50+ await page .click (comments_selector , timeout = 15_000 )
51+ await page .wait_for_load_state ("networkidle" )
4552
46- print ("🎯 Navigated Playwright to Hacker News; Stagehand tracks the same URL ." )
53+ print ("✅ Playwright clicked the first story link ." )
4754
48- print ("🔄 Syncing Stagehand to the current Playwright URL:" , page .url )
55+ print ("🔄 Syncing Stagehand to Playwright's current URL:" , page .url )
4956 await session .navigate (url = page .url )
5057
5158 extract_response = await session .extract (
52- instruction = "extract the primary headline on the page" ,
59+ instruction = "extract the text of the top comment on this page" ,
5360 schema = {
5461 "type" : "object" ,
55- "properties" : {"headline " : {"type" : "string" }},
56- "required" : ["headline " ],
62+ "properties" : {"comment " : {"type" : "string" }},
63+ "required" : ["comment " ],
5764 },
5865 )
5966
0 commit comments