summaryrefslogtreecommitdiff
path: root/facebook_casper.js
blob: 1f5c4e01392be97bc8a232e29e5e220378366afc (plain)
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
98
99
100
101
102
103
var utils   = require('utils');
var fs      = require('fs');
var casper = require('casper').create({
verbose:        true,
logLevel:      "debug",
stepTimeout:    20000,
onStepTimeout: function(){ casper.die("Step timeout", 1); casper.exit() },
pageSettings: {
  loadImages:  false,
  loadPlugins: true,
  userAgent:  "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.8 (KHTML, like Gecko) Chrome/17.0.940.0 Safari/535.8"
},
viewportSize: {
  width:  1280,
  height: 1024
}
}).start();

casper.options.onResourceRequested = function(C, requestData, request) {
    utils.dump("reqData");
    utils.dump(requestData); // here  
    utils.dump("req");
    utils.dump(request); // here  
};
casper.options.onResourceReceived = function(C, response) {
    utils.dump("response");
    utils.dump(response);
};
// so there is 500 on that request for some reason do we have any idea what the request is?  wbell we have request object,
// prints headers and info about it

casper.thenOpen('https://www.facebook.com/?_rdr', function() { //just the facebook login page ok, so need to try add sleep, and then 
//print content again, maybe it just need more time
});
//no good it seems, right? well i think i had same thing, it was because of ssl and ceritifcates, let's try one thing one sec.
casper.waitForSelector("#email", function() {
 this.fill('form#login_form', { 
        email: 'andrew.fenlon@tufts.edu', 
        pass:  '$mnesi42'
    }, true);
//  casper.sendKeys('#email', 'andrew.fenlon@tufts.edu')
//  casper.sendKeys('#pass', '$mnesi42')
//  casper.click('#u_0_l')
//  this.echo(this.getTitle());
});

casper.waitForSelector("#pagelet_welcome_box", function() {
 
});
casper.thenOpen('https://www.facebook.com/photo.php?fbid=108354332830245', function(){
  casper.scrollTo(0,0);
  casper.scrollToBottom();
  fs.write("tmp.html", this.getHTML(), 'w');
  this.waitForSelector('a.UFILikeLink', function(){ } );
  this.waitForSelector('#fbPhotoImage', function(){
    this.waitForSelector('div.like', function(){
//      this.waitForSelector('a.UFILikeLink', function(){ 
////        casper.echo(this.getHTML()) //should I write it to a file? yeah
//        casper.click('button.like_link', function(){ casper.echo("clicked") }); 
// looks good, it sort of click on it, but not sure if js was triggered, or only <a href link yeah no js
// seems impossible? well we can inject js code inside page to click it from inside with jquery not sure if that will working
// we should try though. I'm going to get some sleep for now, can we continue this again sure. thanks a lot no problems
//        this.waitForSelector('a.UFILikeLink', function(){ //so a.UFILikeLink is very important, but isn't loading 
////for some reason...do you know what UFI stands for? nope and there's no way to figure out why it's not working..?
////well i thought that likes are inside iframes or somehting, aren't they? no they're links, and I can click them, but it won't do anything
//// weird right?  looked good, ajax request after link click hmm let's look at that request? is  it possible to? not really 
//any way to check like was set? it wasn't
//I'm able to like from curl, but there's a missing parameter that I'm not seeing in the dom, that's why I was hoping we could
//look at the parameters of that ajax call well with https we can't capture traffic from outside, and phantomjs doesn't have tools 
//to get requests i think, need to check there are couple of things they offer http://phantomjs.org/network-monitoring.html
//should we use this? 
//          casper.echo("hello");
//        }); 
//      })

    });
  });
});
casper.run();
//
//
//
//
//
//
//
//var casper = require('casper').create();
//casper.start('https://www.facebook.com/', function() {
//    this.echo(this.getTitle());
//    this.echo("hellooooooooo");
//});
//casper.then(function(){
////  casper.sendKeys('#email', 'andrew.fenlon@tufts.edu')
////  casper.sendKeys('#pass', '$mnesi42')
////  casper.click('#u_0_l')
//    this.echo(this.getTitle());
//});
////casper.thenEvaluate
////casper.thenOpen('http://phantomjs.org', function() {
////    this.echo(this.getTitle());
////});
//
//casper.run();