Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var casper = require('casper').create({
- // verbose: true,
- // logLevel: "debug",
- pageSettings: {
- userAgent: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36'
- }
- });
- //casper.options.waitTimeout = 1000;
- casper.options.onResourceRequested = function(casper, requestData, request) {
- // If any of these strings are found in the requested resource's URL, skip
- // this request. These are not required for running tests.
- var skip = [
- 'googleads.g.doubleclick.net',
- 'cm.g.doubleclick.net',
- 'www.googleadservices.com',
- 'facebook.com'
- ];
- skip.forEach(function(needle) {
- if (requestData.url.indexOf(needle) > 0) {
- request.abort();
- }
- })
- };
- var LIKE_ID = casper.cli.get('like_id');
- var YOUR_USERNAME = casper.cli.get('username');
- var YOUR_PASSWORD = casper.cli.get('password');
- var url = encodeURIComponent("/p/"+LIKE_ID+"/");
- casper.start('https://www.instagram.com/accounts/login/?force_classic_login', function() {
- });
- casper.then(function() {
- casper.waitForSelector("#login-form", function() {
- this.fillSelectors('form#login-form', {
- 'input[name="username"]': YOUR_USERNAME,
- 'input[name="password"]': YOUR_PASSWORD
- }, true);
- }, function _onTimeout(){
- //this.echo("#thing_" + filename + " not found", "WARNING");
- },1000);
- });
- casper.wait(500, function() {
- casper.wait(1000, function() {
- casper.open('https://www.instagram.com/p/'+LIKE_ID).then(function() {
- });
- casper.waitForSelector("a[href='#']", function() {
- this.click("a[href='#']");
- }, function _onTimeout(){
- this.echo("this.click not found", "WARNING");
- casper.exit();
- },2000);
- });
- casper.wait(500, function() {
- casper.open('https://www.instagram.com/p/'+LIKE_ID).then(function() {
- var json = this.evaluate(function() {
- return window._sharedData;
- });
- if (json['entry_data']['PostPage'][0]['graphql']['shortcode_media']['viewer_has_liked'])
- {
- console.log("LikeDON");
- casper.exit();
- } else {
- console.log("LikeError");
- casper.exit();
- }
- });
- });
- });
- casper.run(function() {
- casper.exit();
- //this.echo('Finished with success!');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement