selenium 网页截图并保存
2021-03-29 04:24
标签:浏览器 exec tab max image imp python log cli from selenium import webdriver login_12306 = webdriver.Chrome(executable_path=r‘D:\python学习\其他\chromedriver.exe‘) password_login = login_12306.find_element_by_xpath(‘/html/body/div[2]/div[2]/ul/li[2]/a‘).click() # 保存网页截图 # 定位验证码图片标签 # 验证码图片左上角坐标、验证码图片长宽 # 电脑分辨率问题,如果 分辨率太大,要乘以相应的倍数 range = (left, top, right, bottom) i = Image.open(‘12306_home.png‘) selenium 网页截图并保存 标签:浏览器 exec tab max image imp python log cli 原文地址:https://www.cnblogs.com/zjj999/p/12612312.html
from PIL import Image
from time import sleep
login_12306.maximize_window() # 设置浏览器全屏
login_12306.get(‘https://kyfw.12306.cn/otn/resources/login.html‘) # 用户发起请求
sleep(0.5)
sleep(0.5)
login_12306.save_screenshot(‘12306_home.png‘)
image_code = login_12306.find_element_by_id(‘J-loginImg‘)
location = image_code.location # {‘x‘: 851, ‘y‘: 193}
size = image_code.size # {‘height‘: 36, ‘width‘: 100}
left = location[‘x‘]*1.5
top = location[‘y‘]*1.5
right = left + size[‘width‘]*1.5
bottom = top + size[‘height‘]*1.5
frame = i.crop(range)
frame.save(‘12306_code.png‘)
上一篇:快速了解匈牙利算法