Is it technically possible to take a screenshot of

2020-02-28 22:46发布

Do you think is technically possible to take a screeshot of a website programmatically?

I would like to craft a scheduled Python task that crawls a list of websites taking an homepage screenshot of them.

Do you think is technically feasible or do you know third party website that offer a service like that (Input: url --> Output: screenshot) ?

Any suggestion?

5条回答
可以哭但决不认输i
2楼-- · 2020-02-28 23:21

You can check webkit2png (only OS X) and khtml2png (Linux) and this post (use PyQt and WebKit).

查看更多
走好不送
3楼-- · 2020-02-28 23:30

How about pyGTK

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."
查看更多
我命由我不由天
4楼-- · 2020-02-28 23:34

It's certainly technically possible.

You would probably have to render the HTML directly onto an image file (or more likely, onto an in-memory bitmap that's written to an image file once completed).

I don't know any libraries to do this for you (apart from a modified WebKit, perhaps)... but there's certainly websites that do this.

Of course, this is a bit more involved than just opening the page in a browser on a machine and taking a screenshot programatically, but the result would likely be better if you don't care about the result from a specific browser.

查看更多
迷人小祖宗
5楼-- · 2020-02-28 23:37

Are you looking for functionality like what browsershots.org offers?

Source code available at Google Code/Browsershots.

查看更多
叼着烟拽天下
6楼-- · 2020-02-28 23:42

I used selenium and PhantomJS.

from selenium import webdriver
driver = webdriver.PhantomJS()
driver.get("http://anyurl.com")
driver.save_screenshot("/path/to/folder")

be sure to place the PhantomJS executable in your $PATH.

查看更多
登录 后发表回答