Mac OS selenium.webdriver.Chrome()---screenshot与Image.crop()的缩放问题

问题描述

selenium.webdriver.Chrome()---screenshot与Image.crop()的缩放问题 Mac OS

先用browser.save_screenshot保存截屏为pic_1.png,使用Image.open(’./learn_result/pic_1.png’).crop((left,top,right,bottom))截取指定矩形元素,最后结果与预期不符,网上能找到windows的解决方法,但找不到Mac os的,最后将(left,top,right,bottom)乘以2得到解决。

browser = webdriver.Chrome()
browser.get(url)
wait = WebDriverWait(browser,5,1)
botton = wait.until(EC.element_to_be_clickable((By.CLASS_NAME,'geetest_radar_tip')))
botton.click()
img = WebDriverWait(browser,20,1).until(EC.presence_of_element_located((By.CLASS_NAME,'geetest_canvas_img')))
time.sleep(2)
location = img.location
size = img.size
top,bottom,left,right = location['y'], location['y']+size['height'],location['x'],location['x']+size['width']
browser.save_screenshot('./learn_result/pic_1.png')
im = Image.open('./learn_result/pic_1.png')

####
#乘以2解决缩放问题
ims = im.crop((left*2,top*2,right*2,bottom*2))
###

ims.save('./learn_result/pic_2.png')

你可能感兴趣的:(python,爬虫)