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

如何在Python+Playwright中获取页面URL?报错求助

问题解决:Playwright获取页面URL报错TypeError

你报错的原因很直接:page.url是Playwright中用于获取当前页面URL的属性,而非可调用的方法。你写的page.url()试图把一个字符串类型的属性当作函数去调用,所以触发了TypeError: 'str' object is not callable错误。

修正后的代码只需要把最后一行的括号去掉:

from playwright.sync_api import sync_playwright
with sync_playwright() as p:
   browser = p.chromium.launch(headless=False, channel='chrome')
   context = browser.new_context(accept_downloads=True)
   page = context.new_page()
   page.goto("https://google.com")
   page.wait_for_timeout(5000)
   pageurl = page.url  # 去掉括号,直接访问属性

这样就能正确获取当前页面的URL了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 17:37:02