-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cjs
48 lines (38 loc) · 1.29 KB
/
test.cjs
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
(async () => {
const DDG = require("duck-duck-scrape")
const searchResults = await DDG.search('how to boil eggs', {
safeSearch: DDG.SafeSearchType.STRICT
});
// DDG.stocks('aapl')
// DDG.currency('usd', 'eur', 1)
// DDG.dictionaryDefinition('happy')
console.log(searchResults);
return;
const url = searchResults.results[0].url
console.log(url)
const options = {
method: 'POST',
headers: {
'x-rapidapi-key': '25ddb299e8msh2c3c672fc41e54ep120933jsn89a98d5bafb0',
'x-rapidapi-host': 'markdown1.p.rapidapi.com',
'Content-Type': 'application/json'
},
body: JSON.stringify({
url
})
};
const response = await fetch('https://markdown1.p.rapidapi.com/html', options);
const result = await response.text();
// console.log(result);
var TurndownService = require('turndown')
var turndownService = new TurndownService()
var markdown = turndownService.remove(['script', 'style']).turndown(result)
// console.log(markdown)
var {Readability} = require('@mozilla/readability');
var {JSDOM} = require('jsdom');
var doc = new JSDOM(result, {url});
parsed_article = new Readability(doc.window.document).parse();
nhm = require('node-html-markdown')
markdown = nhm.NodeHtmlMarkdown.translate(parsed_article.content)
console.log(markdown)
})()