Python Selenium弹出窗口模式中的验证码截图

时间:2015-08-09 23:07:15

标签: javascript python html5 selenium python-imaging-library

所以我试图在我正在抓取的网站上弹出一个CAPTCHA的屏幕截图。 python selenium截图方法driver.save_screenshot(fileLocation)获取整个网站页面的屏幕截图。

然后切换到当前帧并使用以下两个命令获取元素的位置:

element  = driver.find_element_by_xpath(elementXpath)
location = element.location

我遇到的问题是,location方法获取可渲染画布上元素的位置,这似乎与截取的截图图像不匹配。因此,当我尝试使用以下命令裁剪出CAPTCHA时,我将网页的其他部分作为裁剪图像。

#get element size information
size = element.size

#assign crop variables
left   = location['x']
top    = location['y']
right  = location['x'] + size['width']
bottom = location['y'] + size['height']

#crop, show, and save
im  = Image.open(filelocation)
im2 = im.crop((left, top, right, bottom)).save(cropFileLocation)

我错过了一些明显的东西吗?

0 个答案:

没有答案