from selenium import webdriver
from time import sleep
driver = webdriver.Firefox() # 指定和打开浏览器
driver.get('https://www.baidu.com')
sleep(10)
#--------------------------------------------------------------------------------
#下面的方法,只会截图当前程序可见区域内的内容,浏览器框架不会截图
driver.save_screenshot('000.png') #此处会在当前程序目录文件夹下保存照片
driver.save_screenshot('C:\\Users\\del\\Desktop\\新建文件夹\\001.png') #会在桌面的‘新建文件夹’里保存截图,新建文件夹已经存在
driver.get_screenshot_as_file('C:\\Users\\del\\Desktop\\新建文件夹\\002.png') #会在桌面的‘新建文件夹’里保存截图,新建文件夹已经存在
#--------------------------------------------------------------------------------------
driver.close()
======================================================================================================================================
======================================================================================================================================
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.get("https://www.baidu.com")
time.sleep(10)
#--------------------------------------------------------------------------------
picture_time = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
print(picture_time) # 2019-12-11-23_55_12
driver.get_screenshot_as_file('C:\\Users\\del\\Desktop\\新建文件夹\\'+ picture_time +'.png') #保存于桌面已经存在的新建文件夹里:2019-12-11-23_55_12.png
driver.quit()