Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture website screenshot in high resolution?

I want to capture screenshot of a website in high resolution to recognize text or simply to save high quality images. I tried this code in Python 2.7. The website http://www.flaticon.com/ has been taken merely as example.

from selenium import webdriver
import time
driver = webdriver.PhantomJS()
#Setting large window size doesn`t resolve the problem
driver.set_window_size(16000, 12000)
driver.get('http://www.flaticon.com/')
time.sleep(3)
#set resolution 640 dots per inch for this image 
#???
driver.save_screenshot('./downloaded/img/welcome_icons.png') # save a screenshot to disk
driver.close()

It captures screenshot, but the resolution is not enough for me. Enlarging window size doesn`t resolve the problem. The picture from webside reside only on the part of the image. It seems that image resolution is not affected. Is there some way to explicitly set image resolution before saving it?

like image 717
Alexander Avatar asked Sep 20 '16 17:09

Alexander


1 Answers

It's a bit hacky, but I solved this problem for myself by increasing the window size width to 3000 and the zoom to 250%.

driver.set_window_size(3000,800)

driver.execute_script("document.body.style.zoom='250%'")

Hope this helps.

like image 137
Stev3 Avatar answered Nov 14 '22 22:11

Stev3