推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
yh7gdiaYW
V2EX  ›  Python

Python 对网页截图的问题?

  •  
  •   yh7gdiaYW · Sep 22, 2016 · 3790 views
    This topic created in 3557 days ago, the information mentioned may be changed or developed.

    具体来说,有一个带有一堆图表( Echarts )的网页,需求是把这个网页作为报告,发送到某 win 上的邮箱客户端里(可能是 IE6 核心而且有很多限制),考虑到这网页基本不可能显示正常,只能发送图片。
    参考了这篇的方法用 PyQt4 来截图:
    http://www.oschina.net/code/snippet_219811_14920
    然后发现一个问题, Echarts 的图表加载时有个动画效果,截图的话正好就截在动画过程中,翻了下文档也没找到有什么延时的办法?有了解 PyQt4 的吗?或者还有什么更好的轮子可以用?

    8 replies    2016-09-22 14:51:08 +08:00
    TimePPT
        1
    TimePPT  
    PRO
       Sep 22, 2016 via iPhone
    直接取数据再用随便一个 Python 可视化库生成一次比截图省心好维护吧……
    nino
        2
    nino  
       Sep 22, 2016
    wizardoz
        3
    wizardoz  
       Sep 22, 2016
    Echarts 有保存为图片的接口,先把每个单独的图表保存为图片,然后在网页中嵌入图表图片是否可行?
    pathletboy
        4
    pathletboy  
       Sep 22, 2016
    phantomjs
    goofool
        5
    goofool  
       Sep 22, 2016
    In [29]: from selenium import webdriver

    In [30]: driver = webdriver.PhantomJS()

    In [31]: driver.get("http://www.baidu.com")

    In [32]: driver.save_screenshot("test.png")
    Out[32]: True
    soulteary
        6
    soulteary  
       Sep 22, 2016
    使用 js headless 测试工具或许是更好的选择, http://casperjs.org/ 相比较 phantomjs 更简单, api 更友好一点。

    capture() + wait() 两个 api 组合后的效果应该是你要的,如果你愿意, https://github.com/weaver/node-mail 发邮件 , https://github.com/eladnava/mailgen 改一下模版,把图加进去,效果更好。
    yh7gdiaYW
        7
    yh7gdiaYW  
    OP
       Sep 22, 2016
    @wizardoz 会很蛋疼,两位数的图表...
    yh7gdiaYW
        8
    yh7gdiaYW  
    OP
       Sep 22, 2016
    @TimePPT 感觉美观程度比较捉急,另外截图这功能其实不怎么用维护
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   914 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 22:45 · PVG 06:45 · LAX 15:45 · JFK 18:45
    ♥ Do have faith in what you're doing.