PhantomCSSã使ã£ã¦ãã¼ã¸å ã®ç¹å®ã®DOMè¦ç´ ã®ã¿ãç»åã¨ãã¦ä¿åãã
ä»äºã§ã¡ãã£ã¨ãã便å©ãã¼ã«ãä½ãæ©ä¼ããã£ãã®ã§ããã¼ã¸å ã®ç¹å®ã®DOMè¦ç´ ã®ã¿ãç»åã¨ãã¦ä¿åããæ¹æ³ã調ã¹ã¾ããã
PhantomJSãCasperJSã¯å¤å°ä½¿ã£ããã¨ããã£ãã®ã§ãPhantomCSSã¨ããã®ã使ã£ã¦ã¿ããã¨ã«ãã¾ããã
ããã¯ããããç»é¢ã®ãã¹ãã«ä½¿ããã®ã§ã2ã¤ã®ç»åã®å·®åãåãããããªã®ã§ããããã®ä¸é¨ã®æ©è½ã使ããã¨ã§ç®çãéæãããã¨ãã§ãã¾ããã
å°å ¥
åææ¡ä»¶
PhantomJSã¨CasperJSãå¿ è¦ã§ãã
ãããã®ã¤ã³ã¹ãã¼ã«æ¹æ³ã¯å²æãã¾ãã
ã¤ã³ã¹ãã¼ã«
npm
ã§ã¤ã³ã¹ãã¼ã«ã§ãã¾ããã°ãã¼ãã«ã¤ã³ã¹ãã¼ã«ãããã©ããã¯ç°å¢ãã好ã¿ã«åããã¦å¤ãã¦ãã ããã
$ npm install -g phantomcss
使ãæ¹
ãã®ããã°ã®ããããã¼ã¸ã«è¡¨ç¤ºããã¦ããã1件ç®ã®è¨äºãç»åã¨ãã¦ä¿åãããµã³ãã«ã³ã¼ãã¯ãã¡ãã
casper.options.viewportSize = { width: 1280, height: 1024 }; var phantomcss = require('phantomcss') phantomcss.init({screenshotRoot: './screenshots'}) casper.start('http://ariarijp.hatenablog.com/').then(function() { phantomcss.screenshot('#entry-10328749687202579336', 'article'); }).run();
åä½ç¢ºèª
ãã®ã¹ã¯ãªããã以ä¸ã®ããã«å®è¡ãã¾ãã
$ casperjs test sample.js
æ£å¸¸ã«å®è¡ã§ããã°ã以ä¸ã®ãããªãã¡ã¤ã«ãä½æããã¦ããã¯ãã§ãã
screenshots/ `-- article_0.png
ä¿åããç»åã¯ãã®ããã«ãªã£ã¦ãã¾ãï¼å®éã¯è¨äºãã¹ã¦ãå ¥ã£ã¦ããã®ã§ãã£ã¨ç¸¦é·ã§ãï¼
ã¾ã¨ã
ä»ã«ãæ¹æ³ããããããããªããã©ãæå¤ã¨ç°¡åã«ã§ãã¦ããã£ãã