segment-boneyard / nightmare

A high-level browser automation library.
https://open.segment.com
19.55k stars 1.08k forks source link

I would love some help with syntax :) #240

Closed kanethal closed 9 years ago

kanethal commented 9 years ago

You guys have been so great getting to my questions. I'm still struggling up the learning curve with nightmarejs and vo.js and am hoping to get some help on syntax here.

I read the responses for using V2 properly, and the response for URL() returning null was also very helpful. I've been working through the examples and the documentation for vo.js, but I admit I'm still confused on a couple things, any help would be great!

1) the example for console logging the URL includes console.log in parenthesis at the end of the line.

javascript vo(function(){...})

This syntax was also given by Matt in response to the how to use V2 properly issue as a template for using a generator:

javascript vo(function (){yield...}(fn)

What is role of the final parenthesis set? Sorry, I'm sure it's an elementary question.

2) am I correct to assume that the instance if the browser within the generator is persistent? What would be the correct format to use nightmare to navigate to a sight, login, go to another page and grab data and put it into an array, then paginate and continue scraping values for the array, all while maintaining the authentication?

I'm so sorry if this is all very newbish, I'm so excited to be learning your module though and hope the questions are constructive at least :)

matthewmueller commented 9 years ago

no worries man, we were all new to this stuff at one time

1) vo uses a technique called currying. Comes from functional programming, and allows you to progressively build up functions before executing. The reason this is useful is that it allows for you to easily compose pipelines together: vo(vo(...), [vo(...), vo(...)])(done) for example.

Truth be told, I wasn't planning on keeping vo(...) in here, it's just a library that I like. You can easily use nightmare in other ways, using co, promises or callback functions. What I'd like to avoid is like what's going on in the react community, where it's just expected you know ES6, JSX, React and Flux to get started on just about any documentation, so let me know if this is preventing you from understanding nightmare better.

2) Nightmare stores cookies across requests, but not across processes. This means that when your node program ends, the cookies are gone. We may add a way to load cookies, but I think it's actually more resilient to go though the login logic each time as opposed to loading temporary cookies each time. Downside of course is that it's slower and might be suspicious that you're logging into the same account many times.

kanethal commented 9 years ago

Thanks so much Matt. I'm happy to say that after digging way down into the previous issues you guys have already responded to and reading over the test material I have a working version of my script!! I'm so excited :) I'd be happy to submit some of the learning process I went through to get up and running if you think it would help your other novice users! Thanks again. Dan. On Sep 22, 2015 10:06 AM, "Matthew Mueller" notifications@github.com wrote:

no worries man, we were all new to this stuff at one time

1) vo uses a technique called currying https://medium.com/@kbrainwave/currying-in-javascript-ce6da2d324fe. Comes from a functional programming, and allows you to progressively build up functions before executing. The reason this is useful is that it allows for you to easily compose pipelines together: vo(vo(...), [vo(...), vo(...)]) for example.

Truth be told, I wasn't planning on keeping vo(...) in here, it's just a library that I like. You can easily use nightmare in other ways, using co, promises or callback functions. What I'd like to avoid is like what's going on in the react community, where it's just expected you know ES6, JSX, React and Flux to get started on just about any documentation, so let me know if this is preventing you from understanding nightmare better.

2) Nightmare stores cookies across requests, but not across processes. This means that when your node program ends, the cookies are gone. We may add a way to load cookies, but I think it's actually more resilient to build in the login logic each time as opposed to loading temporary cookie files every time. Downside of course is that it's slower and might be suspicious that you're logging into the same account many times.

— Reply to this email directly or view it on GitHub https://github.com/segmentio/nightmare/issues/240#issuecomment-142350807 .