How to take a partial web snapshot in phantomjs using python?
<p>I'm using phantomjs to take a snapshot of a webpage (for example: <a href="http://www.baixaki.com.br/" rel="nofollow">http://www.baixaki.com.br/</a> ) using python.</p>

<p>here is the code:</p>

<pre><code>from selenium import webdriver
driver = webdriver.PhantomJS() # or add to your PATH

driver.get('http://www.baixaki.com.br/')
driver.save_screenshot('screen6.png') # save a screenshot to disk
</code></pre>

<p>The input is a url, the output is an image.
The problem is that the snap shot generated is narrow and long: 
<a href="http://i.stack.imgur.com/hMrZp.png" rel="nofollow"><img src="http://i.stack.imgur.com/hMrZp.png" alt="narrow and long snapshot"></a></p>

<p>I want to capture only what fits in the page without scrolling and full width.
For example, something like this:
<a href="http://i.stack.imgur.com/gNuWV.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/gNuWV.jpg" alt="enter image description here"></a></p>

<ul>
<li>I'm looking for a generic solution not a specific one.</li>
</ul>

<p>Would appreciate your help here. </p>

<p>You could try cropping the image (I'm using Python 3.5 so you may have to adjust to use StringIO if you're in Python 2.X):</p>

<pre><code>from io import BytesIO
from selenium import webdriver
from PIL import Image

if __name__ == '__main__':
    driver = webdriver.PhantomJS('C:&lt;Path to Phantomjs&gt;')
    driver.set_window_size(1400, 1000)
    driver.get('http://www.baixaki.com.br/')
    driver.save_screenshot('screen6.png')
    screen = driver.get_screenshot_as_png()

    # Crop image
    box = (0, 0, 1366, 728)
    im = Image.open(BytesIO(screen))
    region = im.crop(box)
    region.save('screen7.png', 'PNG', optimize=True, quality=95)
</code></pre>

<p>credit where credit is due: <a href="https://gist.github.com/jsok/9502024" rel="nofollow">https://gist.github.com/jsok/9502024</a></p>

python selenium phantomjs