Guest User

Untitled

a guest
Oct 24th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. var page = require('webpage').create();
  2.  
  3. page.open("http://n1k0.github.io/casperjs/#phantom_Casper_captureSelector", function (status) {
  4. if (status !== 'success') {
  5. console.log('Unable to load the address!');
  6. } else {
  7.  
  8. var clipRect = page.evaluate(function () {
  9. return document.querySelector(".span7 demo").getBoundingClientRect(); });
  10. page.clipRect = {
  11. top: clipRect.top,
  12. left: clipRect.left,
  13. width: clipRect.width,
  14. height: clipRect.height
  15. };
  16.  
  17.  
  18.  
  19. window.setTimeout(function () {
  20. page.render('capture.png');
  21. phantom.exit();
  22. }, 200);
  23. }
  24. });
  25.  
  26. var clipRect = page.evaluate(function () {
  27. return document.querySelector(".span7 demo").getBoundingClientRect(); });
  28.  
  29. var clipRect = document.querySelector(".span7 demo").getBoundingClientRect(); });
  30.  
  31. var page = require('webpage').create();
  32.  
  33. page.open("http://n1k0.github.io/casperjs/#phantom_Casper_captureSelector", function (status) {
  34. if (status !== 'success') {
  35. console.log('Unable to load the address!');
  36. } else {
  37. window.setTimeout(function () {
  38. //Heres the actual difference from your code...
  39. var bb = page.evaluate(function () {
  40. return document.getElementsByClassName("span7 demo")[0].getBoundingClientRect();
  41. });
  42.  
  43. page.clipRect = {
  44. top: bb.top,
  45. left: bb.left,
  46. width: bb.width,
  47. height: bb.height
  48. };
  49.  
  50. page.render('capture.png');
  51. phantom.exit();
  52. }, 200);
  53. }
  54. });
  55.  
  56. var page = require('webpage').create();
  57.  
  58. page.open("https://www.sejlar.com/maps.html", function (status) {
  59. if (status !== 'success') {
  60. console.log('Page not found');
  61. }
  62. else {
  63. var p = page.evaluate(function () {
  64. return document.getElementById('map').getBoundingClientRect();
  65. });
  66.  
  67. page.clipRect = {
  68. top: p.top,
  69. left: p.left,
  70. width: p.width,
  71. height: p.height
  72. };
  73.  
  74. page.render('screenshot.png');
  75. phantom.exit();
  76. }
  77. });
  78.  
  79. return JSON.stringify(document.getElementsByClassName("span7 demo")[0].getBoundingClientRect();
  80.  
  81. return JSON.stringify(document.getElementsByClassName("span7 demo")[0].innerHTML);
Add Comment
Please, Sign In to add comment