Web Bot Tutorial - Auto Post to Craigslist - 4/4 - Modules and Asynchronous Code with Nightmare.js

Published: 03 November 2016
on channel: Powerslacker
1,901
37

FULL CODE & MORE LIKE THIS: http://blog.breakthru.solutions/auto-...

Vo.js: https://github.com/matthewmueller/vo

Javascript is asynchronous meaning that different task can execute at the same time. Normally this a good thing but when you are trying to get a web bot to do things in a specific order its pretty awful. The typical way of dealing with would be to use call backs. But if you do that….it crashes.
So it turns out that nightmare actually uses promises to perform all its actions in a “synchronous” manner. So when you run a nightmare instance and assign those to a function what happens is that it “promises” to do everything youve told it to do. However, when you run it in a loop - nightmare promises to do the work, then the loop accepts the promise as valid AND moves on to the next task on its list. If that task is another nightmare instance then the two nightmare instances try to use the same browser at the same time. Both nightmare instances give up on life and crash your program.


Theres a couple way we can deal with this. However, the one I like best is generators. Generators are a new feature in javascript. You can think of a generator as a “pauseable” function. This makes your javascript behave the way you would expect code to execute in almost every other programming language.


Watch video Web Bot Tutorial - Auto Post to Craigslist - 4/4 - Modules and Asynchronous Code with Nightmare.js online without registration, duration hours minute second in high quality. This video was added by user Powerslacker 03 November 2016, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1,901 once and liked it 37 people.