我正在通过phantomjs捕获URL的屏幕截图。
我使用phantomjs驱动程序执行了该操作,但是捕获一张屏幕截图大约需要2秒钟。
driver = webdriver.PhantomJS('path/to/phantomjs.exe')
def driver_initialize(width,height):
driver.set_script_timeout(30)
if width and height:
driver.set_window_size(width, height)
def driver_screenshot(urls):
green_color=[]
for i in urls:
print(i)
filename = i.split("/")[4] + ".png"
screen_path = os.path.join(path, filename)
images.append(screen_path)
driver.get(i)
driver.save_screenshot(screen_path)
def driver_quit():
driver.quit()
driver_initialize(1024,768)
driver_screenshot(links)
driver_quit()
使用此代码,每个屏幕快照的捕获和保存过程大约需要3-4秒。我需要处理100万个网址。如何优化此代码?