2

I've an idea and want to implement it. But I'm not sure if it's gonna work. So, wanted to get your inputs.

 I would like to take screenshots of a url. 

Say, when I open a web-site www.espncricinfo.com , I would like to take screenshot of that page and save locally. This saved image can be converted to GIF later on. Can this be achieved through python ? Any suggestions/inputs to make it ?

Updated

And also is it possible to capture screenshot in headless-browser ?

Any possibilities to launch the browser in headless mode (non-GUI) and then take the screenshot of particular area of web-page ?

StackGuru
  • 471
  • 1
  • 9
  • 25
  • I just googled "take screenshots with python" and this came up -https://pypi.org/project/pyscreenshot/. Pretty sure that does what you need... – DannyMoshe Mar 27 '19 at 19:54
  • Any possibilities to launch the browser in `headless mode` (non-GUI) and then take the screenshot of particular area of web-page ? – StackGuru Mar 30 '19 at 08:28

3 Answers3

2

To take a screenshot using python:

import pyscreenshot as ImageGrab

im = ImageGrab.grab()

im.save('path/to/image/folder/image_name.png')

im.show()
DannyMoshe
  • 6,023
  • 4
  • 31
  • 53
  • 2
    Yeah, this captures the entire page screenshot. Is it possible to capture only specified area or some images/graphs in the web-page ? – StackGuru Mar 28 '19 at 05:03
  • 1
    Although that's now a separate question (i believe i already answered yours). Yes, the docs explain how to capture 'part' of the screen - https://pypi.org/project/pyscreenshot/#description. . – DannyMoshe Mar 28 '19 at 16:14
  • Any possibilities to launch the browser in `headless mode` (non-GUI) and then take the screenshot of particular area of web-page ? – StackGuru Mar 30 '19 at 08:28
  • Yes you can definitely achieve this with Selenium or Splinter in Python. Basically you can run some tests (setting your inputs), pause those tests and then run an ImageGrab. – DannyMoshe May 03 '19 at 20:34
0

Yes and no, if you send a request with urllib you will get the HTML in return, which is step one to displaying a webpage. But you have to build that webpage from that with a browser engine, otherwise all you will see is a bunch of text.

There are some python libraries that can do this, such as pywebkitgtk, but those are probably not going to give you the best experience and support.

Another thing you could try is to use crod and firefox/chrome/whatever and then use python to automate the process.

Oh, and by the way, I strongly recommend upgrading to python3

Joeri
  • 626
  • 5
  • 18
0

I know it is a bit to late now, but just saw this question and in case anyone else is looking for a mighty tool, to do screenshots and also use headless browsers with python... I just want to recommend to look more deeply into https://www.seleniumhq.org/. There are many tutorials on youtube available. However, this is IMHO the most accurate framework to execute your task, IMHO. To make screenshots, you can then define the screen resolution etc.

FDE
  • 31
  • 2
  • 10