Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a website where I have to take weekly screen shots of sister sites. I was wondering how this maybe done. I had obtained the code for taking screen shots but have no idea how to open up the browser at a set particular time so that the website screen shots maybe taken. I understood that I had to use crontab to schedule my tasks but how to open the browser?

My script to take screen shots is as follows

import gtk.gdk

w = gtk.gdk.get_default_root_window()
sz = w.get_size()
#print "The size of the window is %d x %d" % sz
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])
pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])
if (pb != None):
    pb.save("screenshot.png","png")
 #   print "Screenshot saved to screenshot.png."
else:
 #   print "Unable to get the screenshot."

Any idea how to to open the browser via a python script?

I'm open to suggestions if this is not the right way to implement my idea.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Well it so happens that I found the answer to my question. :D

#!/usr/bin/python
import webbrowser
webbrowser.open("http://www.google.com")

Thats all it takes in a python script to open google using python. Cheers. :D

share|improve this answer

You could use a third-party service that does it all for you. GrabzIt is one example. You first request a URL is turned into a screenshot like so.

import GrabzItClient

#Create the GrabzItClient class
#Replace "APPLICATION KEY", "APPLICATION SECRET" with the values from your account!
grabzIt = GrabzItClient.GrabzItClient("APPLICATION KEY", "APPLICATION SECRET")
#Take the picture the method will return the unique identifier assigned to this task
id = grabzIt.TakePicture("http://www.google.com", "http://www.example.com/GrabzItHandler.py")

Then you can download the image and save it where you like.

#Wait for a while

result = grabzIt.GetPicture(id)

if result != None:
    #Ensure that the application has the correct rights for this directory.
    fo = open("images" + os.sep + filename, "wb")
    fo.write(result)
    fo.close()

You can find more information in thier Python API.

share|improve this answer
    
ya.. I didn't know about such an option..but then its someone else's work.. not my effort.. no pride in it.. THanks though –  Shyam K May 29 '12 at 20:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.