• 技术文章 >Python技术 >Python基础教程

    Python如何截图保存?

    十一十一2021-03-04 09:32:47原创4009

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    一般在测试的时候,经常会遇到代码报错等问题,这种需要反馈的时候,就需要利用到python自行截图。

    1、selenium for python

    实现代码如下:

    import time
    from selenium import webdriver
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.implicitly_wait(6)
    driver.get("https://www.baidu.com")
    time.sleep(1)
    driver.get_screenshot_as_file("C:\\baidu.png")
    driver.quit()

    2、PIL库

    实现代码如下:

    import time
    from PIL import ImageGrab
    if __name__=="__main__": 
      pic = ImageGrab.grab()
      pic.save("picture.jpg")

    依赖这两种方式,足够大家实现python截图了,感兴趣的小伙伴可以跟着小编一起操作起来啦。

    专题推荐:python截图保存
    品易云
    上一篇:python关键字有哪些?怎么看? 下一篇:python cutecharts库如何使用?

    相关文章推荐

    • python中scikit-learn是什么?• python关键字有哪些?怎么看?

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网