以开放的网站在python脚本截图 [英] Take a screenshot of open website in python script

查看:214
本文介绍了以开放的网站在python脚本截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要写这将打开一个网站,并在网站完全地打开它需要打开的网站的截图python脚本。

I need to write a python script which opens a website and when the website is completly opened it takes a screenshot of the opened website.

我写了某事是这样的:

import webbrowser
import wx

wx.App()
link = "http://stackoverflow.com/questions"
webbrowser.get('firefox %s').open_new_tab(link)
screen = wx.ScreenDC()
size = screen.GetSize()
bmp = wx.EmptyBitmap(size[0], size[1])
mem = wx.MemoryDC(bmp)
mem.Blit(0, 0, size[0], size[1], screen, 0, 0)
del mem
bmp.SaveFile('screenshot.png', wx.BITMAP_TYPE_PNG)

它只是打开在Firefox一个新的标签,但它不采取它的屏幕截图:(

It only opens a new tab in firefox but it doesnt take a screenshot of it :(

我想要的解决方案是跨平台的。感谢您的帮助:)

I want the solution to be cross-platform. Thanks for any help:)

编辑:

这里的主要问题是,脚本musnt拍照前我的网页被完全地打开。如何解决这个问题?

推荐答案

此解决方案是相当跨平台的,但如果你想显示有点网页与菜单/工具栏等桌面开.. 。这不是你想要的。

This solution is fairly cross-platform, but if you're trying to show a bit of a web page open in a desktop with menu/toolbars etc... it's not what you want.

您可以使用 SeleniumHQ 自动化您选择的浏览器中,有一个浏览器渲染页面,然后得到完整的在渲染页面的图像 - 也就是说,不只是说的显示在屏幕上的页面部分的屏幕截图。然后,您可以裁剪的相应。

You could use SeleniumHQ to automate a browser of your choice, have that browser render the page, then get the complete image of the rendered page - ie, not just a screenshot of the portion of the page that's displayed on screen. You could then crop that accordingly.

这篇关于以开放的网站在python脚本截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆