python 截图 撕裂_python 截图screenshot处理

from selenium import webdriver

from selenium.webdriver.common.action_chains import ActionChains

import time

import os

def screenshot(driver,file_path = None):

#用户没有传参数

if file_path == None:

project_path = os.path.dirname(os.getcwd())

print(project_path)

file_path = project_path +"/images/"

if not os.path.exists(file_path):

os.mkdir(file_path)

images_name = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())

file_path = file_path+images_name+".png"

print(file_path)

driver.save_screenshot(file_path)

try:

driver = webdriver.Chrome()

driver.maximize_window()

url = "https://www.cnblogs.com/"

driver.get(url)

ele = driver.find_element_by_xpath('//*[@id="cate_item_2"]')

ActionChains(driver).move_to_element(ele).perform()

driver.find_element_by_partial_link_text('python').click()

time.sleep(3)

# driver.save_screenshot('jietu1.png')

#浏览器句柄切换

#先获取浏览器所有句柄

handles = driver.window_handles

#当前浏览器句柄

current_handles = driver.current_window_handle

#for循环句柄

for handle in handles:

#如果handle不是当前handle

if handle != current_handles:

#handle就句柄切换一下

driver.switch_to.window(handle)

screenshot(driver)#自己写的screenshot

“”“

#浏览器句柄切换

#先获取浏览器所有句柄

handles = driver.window_handles

#当前浏览器句柄

current_handles = driver.current_window_handle

#for循环句柄

for handle in handles:

#如果handle不是当前handle

if handle != current_handles:

#handle就句柄切换一下

driver.switch_to.window(handle)

#screenshot(driver)#自己写的screenshot

driver.save_screenshot("jietu22.png")

”“”

finally:

time.sleep(3)

driver.quit()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值