New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Looping through pages when next is available #402
Comments
A hastily thrown together sample: var Nightmare = require('nightmare');
var vo = require('vo');
vo(run)(function(err, result) {
if (err) throw err;
});
function* run() {
var nightmare = Nightmare(),
MAX_PAGE = 10,
currentPage = 0,
nextExists = true,
links = [];
yield nightmare
.goto('https://www.yahoo.com')
.type('.input-query', 'github nightmare')
.click('#search-submit')
.wait('body')
nextExists = yield nightmare.visible('.next');
while (nextExists && currentPage < MAX_PAGE) {
links.push(yield nightmare
.evaluate(function() {
var links = document.querySelectorAll("ol.searchCenterMiddle a");
return links[0].href;
}));
yield nightmare
.click('.next')
.wait('body')
currentPage++;
nextExists = yield nightmare.visible('.next');
}
console.dir(links);
yield nightmare.end();
} You could, of course, remove the |
Thank you @rosshinkley |
@rosshinkley I can't get your script to run. It gives the following error: "Cannot read property 'focus' of null". Does it still run for you? |
Nevermind, I just had to update the script a bit.
|
@misbach I'm still missing the last page, even with the updated script. |
This was helpful Thanks a lot. |
Hi All,
What would be the best way to keep looping the browsing while a "next" link is available and then return the result to the main process.
The below example returns the first search result for the first page. How to result all first links from each search page?
The text was updated successfully, but these errors were encountered: