Chinaunix首页 | 论坛 | 博客
  • 博客访问: 536874
  • 博文数量: 142
  • 博客积分: 2966
  • 博客等级: 少校
  • 技术积分: 1477
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-07 22:37
文章分类

全部博文(142)

文章存档

2013年(3)

2012年(21)

2011年(53)

2010年(33)

2009年(32)

分类: Python/Ruby

2012-04-29 12:40:15


点击(此处)折叠或打开

  1. ----------------CaptureImageJS.py----------------------------
  2. '''
  3. By Jibo He @ueseo.org
  4. hej...@ueseo.org
  5. capture web page screen under ubuntu server
  6. '''

  7. import os
  8. import subprocess

  9. xvfb ='xvfb-run'
  10. PHANTOM = '/home/hejibo1984/bin/phantomjs'

  11. APP_ROOT = '/home/hejibo1984/test'
  12. #APP_ROOT = os.path.dirname(os.path.realpath(__file__))

  13. SCRIPT = os.path.join(APP_ROOT, 'screenshot.js')

  14. url =''
  15. outfile = '/home/hejibo1984/test/ueseo.png'
  16. params = [xvfb,PHANTOM, SCRIPT, url, outfile]
  17. exitcode = subprocess.call(params)
  18. print exitcode

  19. ---------------------screenshot.js---------------------

  20. var page = new WebPage(),
  21.     address, outfile, width, height, clip_height;
  22. address = phantom.args[0];outfile = phantom.args[1];width =
  23. 1024;clip_height = height = 800;
  24. page.viewportSize = { width: width, height: height };page.clipRect = {
  25. width: width, height: clip_height };
  26. page.open(address, function (status) {
  27.   if (status !== 'success') {
  28.     phantom.exit(1);
  29.   } else {
  30.     page.render(outfile);
  31.     phantom.exit();
  32.   }});

===========================================================================================

点击(此处)折叠或打开

  1. ---------------------------截图代码 --------------------------------
  2. #!/usr/bin/env python
  3. '''
  4. capture the web page

  5. '''
  6. from selenium import webdriver

  7. browser = webdriver.Firefox()
  8. browser.get('/')
  9. browser.save_screenshot('ueseo.png')
  10. browser.close()


============================================================================================

  这个东西应该比较稳定,是转pdf的,不过我没试过,如果要转图片,用imagemagick再转吧 

也可看看这个: http://cutycapt.sourceforge.net/ 



阅读(656) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~