views:

1355

answers:

4

Hi all

What I want to achieve is to get a website screenshot from any website in python.

Env: Linux

A: 

Scrot

cpharmston
A: 

You don't mention what environment you're running in, which makes a big difference because there isn't a pure Python web browser that's capable of rendering HTML.

But if you're using a Mac, I've used webkit2png with great success. If not, as others have pointed out there are plenty of options.

Daniel
+3  A: 

On the Mac, there's webkit2png and on Linux+KDE, you can use khtml2png. I've tried the former and it works quite well, and heard of the latter being put to use.

I recently came across QtWebKit which claims to be cross platform (Qt rolled WebKit into their library, I guess). But I've never tried it, so I can't tell you much more.

The QtWebKit links shows how to access from Python. You should be able to at least use subprocess to do the same with the others.

ars
+2  A: 

I can't comment on ars's answer, but I actually got Roland Tapken's code running using QtWebkit and it works quite well.

Just wanted to confirm that what Roland posts on his blog works great on Ubuntu. Our production version ended up not using any of what he wrote but we are using the PyQt/QtWebKit bindings with much success.

aezell
Cool. I think that's the lib I'll try the next time I need something like this.
ars
We ended up putting a RabbitMQ server on top of it and building some code the control the Xvfb servers and the processes running in them to pseudo-thread the screenshots being built. It runs decently fast with an acceptable amount of memory usage.
aezell