使用selenium和phantomjs的脚本可以检查大约20个动态页面,并在没有屏幕截图部分的情况下警告我发生更改时可以快速运行,但是当我想要获取页面的屏幕截图时,大约需要1-2分钟来警告我并获取屏幕截图.有没有更好,更快的方法来使用python截取页面特定部分的屏幕截图?
这是我用于屏幕截图的代码.
from selenium import webdriver
from PIL import Image
fox = webdriver.Firefox()
fox.get('https://stackoverflow.com/')
# now that we have the preliminary stuff out of the way time to get that image :D
element = fox.find_element_by_id('hlogo') # find part of the page you want image of
location = element.location
size = element.size
fox.save_screenshot('screenshot.png') # saves screenshot of entire page
fox.quit()
im = Image.open('screenshot.png') # uses PIL library to open image in memory
left = location['x']
top = location['y']
right = location['x'] + size['width']<