-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
87 lines (76 loc) · 2.76 KB
/
index.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
const request = require('request-promise');
const express = require('express');
const app = express();
const fs = require('fs');
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const util = require('util')
const parse_url = (input_url) => {
const options = {
uri: input_url,
headers: {
'User-Agent': 'Request-Promise'
},
};
request(options)
.then((htmlString) => {
// Process html...
//console.log(htmlString);
const dom = new JSDOM(htmlString, { runScripts: "dangerously"});
const { window } = dom;
console.log(JSON.stringify(window.document.getElementsByClassName('sqs-audio-embed')[0], null, 4));
console.log(window.document.querySelector("div"));
console.log(window.document.head.querySelector("audio"));
console.log(window.document.body.querySelector("audio"));
// console.log(JSON.stringify(window.document.body, null, 4));
// console.log(util.inspect(window.document, false, null));
fs.writeFile('page.html', htmlString, (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
})
.catch((err) => {
// Crawling failed...
console.log(err);
});
};
parse_url('https://fireandfragrance.com/podcasts/2017/1/15/andy-byrd-boundless-love');
/*
jsdom.env({
html: 'https://fireandfragrance.com/podcasts/2017/1/15/andy-byrd-boundless-love',
scripts: ["https://code.jquery.com/jquery-2.1.1.js"]
}, (err, window) => {
console.log(window);
});
var phantom = require('x-ray-phantom');
var Xray = require('x-ray');
var x = Xray()
.driver(phantom());
x('https://fireandfragrance.com/podcasts/2017/1/15/andy-byrd-boundless-love', 'title')(function(err, str) {
if (err) return done(err);
assert.equal('Google', str);
done();
})
*/
// jsdom.env({
// html: 'https://fireandfragrance.com/podcasts/2017/1/15/andy-byrd-boundless-love',
// scripts: ['http://code.jquery.com/jquery.js'],
// done: (function (errors, window) {
// var $ = window.$;
// // we're interested in the title, subreddit, URL,
// // score, and the number of comments for each link
// var stories = $.map($('#siteTable .thing'), function (thing) {
// return {
// title: $('a.title', thing).text(),
// subreddit: $('a.subreddit', thing).text(),
// href: $('a.title', thing).attr('href'),
// score: $('.score.unvoted', thing).text(),
// numComments: $('a.comments', thing).text().match(/^[0-9]*/)[0] || 0
// };
// });
//
// console.log(stories);
//
// })
// });
app.listen(3000, () => console.log('Example app listening on port 3000.'));