forked from HowHai/Tiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphantomServer.js
97 lines (76 loc) · 2.86 KB
/
phantomServer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var phantom = require('phantom');
phantom.create(function(ph) {
return ph.createPage(function(page) {
return page.open('http://uncrate.com/', function(status) {
console.log(status);
page.injectJs('http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',function() {
// setTimeout(function() {
page.evaluate(function() {
var images = [];
function getImgDimensions($i) {
return {
top : $i.offset().top,
left : $i.offset().left,
width : $i.width(),
height : $i.height()
}
}
console.log(jQuery('article .item img').length);
// jQuery('article .item img').each(function() {
// var img = getImgDimensions(jQuery(this));
// images.push(img);
// });
$('.article-list.grid li .image-wrapper img').each(function() {
var img = getImgDimensions($(this));
images.push(img);
});
return images;
}, function(result) {
result.forEach(function(imageObj, index, array){
page.set('clipRect', imageObj);
page.render('images/' + index + '.png');
});
ph.exit();
});
// }, 1000);
});
});
});
});
// var phantom = require('phantom');
// phantom.create(function(ph) {
// return ph.createPage(function(page) {
// return page.open('https://twitter.com/', function(status) {
// console.log('page loaded:', status);
// page.set('clipRect', { top: 186, left: 22, width: 179, height: 134 });
// page.render('twitter5.png');
// ph.exit();
// });
// });
// });
// var phantom = require('phantom');
// phantom.create(function(ph) {
// return ph.createPage(function(page) {
// return page.open('http://www.thisiswhyimbroke.com/new/', function(status) {
// console.log('opened site?', status);
// page.injectJs('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', function() {
// //jQuery loaded.
// // Wait a bit for AJAX content to load on the page.
// setTimeout(function() {
// return page.evaluate(function() {
// // Get what you want from page using jQuery.
// var titleArr = [];
// var contentArr = [];
// titleArr.push(jQuery('article h1 a')[0].text);
// contentArr.push(jQuery('article .details .desc p')[0].innerText);
// // $(".listEntry h3 a").each(function() {
// // titleArr.push($(this)[0].text);
// // });
// // page.render('twitter.png');
// return {name: titleArr[0], content: contentArr[0], imgUrl: 'photo1.jpg'};
// });
// }, 1000);
// });
// });
// });
// });