如何从网页制作截图? [重复]

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何从网页制作截图? [重复]相关的知识,希望对你有一定的参考价值。

这个问题在这里已有答案:

如何从任何网址(网页)制作屏幕截图?

我在努力:

from .ghost import Ghost
ghost = Ghost(wait_timeout=4)
ghost.open('http://www.google.com')
ghost.capture_to('screen_shot.png')

结果:

No module named '__main__.ghost'; '__main__' is not a package

我也在尝试:

Python Webkit making web-site screenshots using virtual framebuffer

Take screenshot of multiple URLs using selenium (python)

Fastest way to take a screenshot with python on windows

Take a screenshot of open website in python script

我也尝试过其他未列出的方法。什么都没有成功。或者找不到错误或模块..或或或。我累了。有没有一种简单的方法来使用Python 3.X制作网页的屏幕截图?

upd1:

C:prgPYPUMA	ests>py save-web-html.py
Traceback (most recent call last):
File "save-web-html.py", line 2, in <module>
from .ghost import Ghost
ModuleNotFoundError: No module named '__main__.ghost'; '__main__' is not a package

UPD2:

C:prgPYPUMA	ests>py save-web-html.py
Exception ignored in: <bound method Ghost.__del__ of <ghost.ghost.Ghost object at 0x0000020A169CF860>>
Traceback (most recent call last):
  File "C:UsersCoarAppDataLocalProgramsPythonPython36libsite-packagesghostghost.py", line 325, in __del__
    self.exit()
  File "C:UsersCoarAppDataLocalProgramsPythonPython36libsite-packagesghostghost.py", line 315, in exit
    self._app.quit()
AttributeError: 'NoneType' object has no attribute 'quit'
Traceback (most recent call last):
  File "save-web-html.py", line 4, in <module>
    ghost = Ghost(wait_timeout=4)
TypeError: __init__() got an unexpected keyword argument 'wait_timeout'
答案

在80年代后期,这可能是一个简单的任务,只需将一些html渲染到图像而不是屏幕。

但是现在,网页需要客户端执行来构建其DOM的一部分,并根据客户端发起的AJAX(或等效)请求重新呈现......这完全是“web 2.0”的事情。

渲染一个像http://google.com这样的网站作为一个简单的html返回应该很容易,但渲染像https://www.facebook.com/https://www.kogan.com/这样的东西会有许多后面和第四个通信来显示你期望看到的东西。

因此将其限制为纯python解决方案可能并不合理;我不知道基于python的浏览器。考虑运行单独的服务来截取屏幕截图,并使用您的核心应用程序(在python中)获取请求的屏幕截图。

我刚尝试了几个与docker,其中许多人与https和前面提到的ajax行为斗争。

earlyclaim/docker-manet似乎工作demo page

编辑:从您的评论中,您需要使用第二个请求呈现的图表中的数据。

你只需要从https://www.minnowbooster.net/limit/chart回来的json

try:
    from urllib.request import urlopen  # py3
except ImportError:
    from urllib2 import urlopen  # py2
import json

url = 'https://www.minnowbooster.net/limit/chart'

response = urlopen(url)
data_str = response.read().decode()
data = json.loads(data_str)

print(data)

以上是关于如何从网页制作截图? [重复]的主要内容,如果未能解决你的问题,请参考以下文章

在当前的android片段中禁用屏幕截图[重复]

如何使用Android片段管理器传递变量[重复]

使用selenium webdriver使用java [重复]查看页面源代码的屏幕截图

Android:如何从资产中播放视频?

如何从片段获取数据到另一个活动? (不是容器活动)[重复]

如何使用视图绑定从片段更改父活动中的视图[重复]