Almaatla commited on
Commit
ba8beb5
·
unverified ·
1 Parent(s): cf1b8dc

Add files via upload

Browse files
Files changed (1) hide show
  1. phantomjs/news_ubuntu.js +54 -0
phantomjs/news_ubuntu.js ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use strict";
2
+ var page = require('webpage').create(),
3
+ system = require('system'),
4
+ address;
5
+
6
+ if (system.args.length === 1) {
7
+ console.log("Latest news by duckduckgo.com");
8
+ console.log('Usage: news.js <some keyword>');
9
+ phantom.exit(1);
10
+ } else {
11
+ address = "https://duckduckgo.com?q=" + system.args[1] + "&t=h_&iar=news&ia=news";
12
+
13
+ page.onConsoleMessage = function(msg){
14
+ //console.log(msg);
15
+ system.stderr.writeLine('console: ' + msg);
16
+ };
17
+
18
+ page.open(address, function (status) {
19
+ if (status !== 'success') {
20
+ console.log('FAIL to load the address');
21
+ }
22
+
23
+ setTimeout(pEval, 1000);
24
+
25
+ window.setTimeout(function () {
26
+ page.render("photo.png");
27
+
28
+ console.log("ok");
29
+
30
+
31
+ phantom.exit();
32
+ }, 2500);
33
+
34
+ });
35
+ }
36
+
37
+ function pEval(){
38
+ return page.evaluate(function() {
39
+
40
+ var a = document.querySelectorAll("a.result__a");
41
+ console.log(a.length);
42
+ var results=[];
43
+ for(var i=0;i<a.length;i++){
44
+ results.push({"text":a[i].textContent,"url":a[i].href});
45
+ };
46
+ console.log(results.length);
47
+ for(var i=0;i<results.length;i++){
48
+ console.log(results[i].text);
49
+ console.log(results[i].url);
50
+ };
51
+ return ;
52
+ });
53
+ }
54
+