-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest-phantom.js
51 lines (41 loc) · 1.13 KB
/
test-phantom.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
var phantom = require('phantom');
var cheerio = require('cheerio');
var url = require('url');
var instance = null;
var page = null;
phantom.create().then((res) => {
instance = res;
return instance.createPage();
}).then((res) => {
page = res;
page.on("onResourceRequested", (requestData) => {
console.info('Requesting', requestData.url)
});
return page.open('http://sreality.cz/hledani/pronajem/byty');
}).then((status) => {
console.log(status);
return page.property('content');
}).then((content) => {
console.log(content);
var $ = cheerio.load(content);
$('a.btn-paging').each(function() {
var tmpUrl = 'http://sreality.cz' + $(this).attr('href');
var parsedUrl = url.parse(tmpUrl);
console.log({
type: 'url',
url: tmpUrl,
processor: 'sreality.cz/listing'
});
});
$('span.basic > h2 > a').each(function() {
var tmpUrl = 'http://sreality.cz' + $(this).attr('href');
var parsedUrl = url.parse(tmpUrl);
console.log({
type: 'url',
url: tmpUrl,
processor: 'sreality.cz/details'
});
});
console.log('Done, exitting.');
return instance.exit();
});