Sync_playwright()。start()似乎已悬挂
我写的简单代码:
from playwright.sync_api import sync_playwright
print('debug1')
p = sync_playwright().start()
print('debug2')
browser = p.firefox.launch(headless=False)
print('debug3')
page = browser.new_page()
page.goto("http://whatsmyuseragent.org/")
page.screenshot(path="example.png")
browser.close()
我得到的输出:
debug1
我是使用剧作家库的完整菜鸟,并且该程序只是挂在'sync_playwright()。start()'零件上。我已经尝试从Internet运行其他示例脚本,所有这些脚本都在这一行上冻结了。另外,我尝试使用更改浏览器并使用无头模式,所有这些模式都无法使用。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该使用
sync_playwright
用作:输出
请参阅Python
编辑(特定于op)
作为最后的沟渠工作,请尝试以下步骤:
pip install -u pip
pip卸载plawyright
pip缓存删除playwright
pip install playwright
请记住,如果您安装了多个版本的Python,请使用为PIP定义的PATH变量,用于Python 您想要安装剧作家。最后,尝试更改与剧作家一起使用的浏览器。因此,代替
浏览器= p.firefox.launch(headless = false)
,使用browser = p.chromium.launch(headless = false)
>You are supposed to use
sync_playwright
as a context managers:Output
See playwright documentation for python here
Edit (specific to OP)
As a last ditch effort, try these steps in order:
pip install -U pip
pip uninstall plawyright
pip cache remove playwright
pip install playwright
Keep in mind that if you have installed multiple versions of python, use the PATH variable defined for pip for the version of python you want to install playwright in. Lastly, try changing the browser you use with playwright. So instead of
browser = p.firefox.launch(headless=False)
, usebrowser = p.chromium.launch(headless=False)
也可以使用async_playwright尝试相同的方法:
Same can be tried with async_playwright as well:
我遇到了这个问题,它是通过重新安装和升级PIP来解决的。我不知道为什么。
I had this issue and it was solved by reinstalling and upgrading pip. I have no idea why.