使用 python playwright 下载 currnet 图像
是否可以使用 Playwright 制作类似的东西:
https://stackoverflow.com/a/52692041
import base64
img_base64 = browser.execute_script("""
var ele = arguments[0];
var cnv = document.createElement('canvas');
cnv.width = ele.width; cnv.height = ele.height;
cnv.getContext('2d').drawImage(ele, 0, 0);
return cnv.toDataURL('image/jpeg').substring(22);
""", browser.find_element_by_xpath("//your_xpath"))
with open(r"image.jpg", 'wb') as f:
f.write(base64.b64decode(img_base64))
我更喜欢 playwright 而不是 selenium,但是找不到剧作家的方法。
Is it possible to make something like this with Playwright:
https://stackoverflow.com/a/52692041
import base64
img_base64 = browser.execute_script("""
var ele = arguments[0];
var cnv = document.createElement('canvas');
cnv.width = ele.width; cnv.height = ele.height;
cnv.getContext('2d').drawImage(ele, 0, 0);
return cnv.toDataURL('image/jpeg').substring(22);
""", browser.find_element_by_xpath("//your_xpath"))
with open(r"image.jpg", 'wb') as f:
f.write(base64.b64decode(img_base64))
I prefer playwright over selenium but can't find a way with Playwright.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试了这个并且它有效(我使用元素处理程序而不是 arguments[0]):
I tried this and it worked (I used an element handler instead of arguments[0]):