I'm trying to learn CasperJS and for a start I would like to create small yummly.com scraper. I want to scrape a list of 100-1000 popular recipes.
Everything was going great till I tried to click on the element that triggers more recipes to load. I've tried every way, xpath, selector, label. I really don't know what could be the problem.
Here is my code:
var utils = require('utils');
var casper = require('casper').create({
verbose: true,
logLevel: 'error',
pageSettings: {
loadImages: false,
loadPlugins: false,
userAgent: 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36'
}
});
var url = "http://www.yummly.com/browse/popular-now";
var x = require('casper').selectXPath;
function getLinks() {
var links = document.querySelectorAll('div.y-title a');
return Array.prototype.map.call(links, function(e) {
return e.getAttribute('href');
});
}
casper.start(url, function() {
console.log(this.getTitle());
});
// Try to click with xpath
casper.wait(2000, function() {
casper.click(x('//*[@id="more"]'));
});
// Try to click with label
casper.wait(2000, function() {
this.clickLabel('See more', 'a');
});
// Try to click with selector
casper.wait(2000, function() {
casper.click('#more');
});
// Try to wait for selector
casper.waitForSelector('#more', function() {
this.click('#more');
casper.wait(2000, function(){
links = this.evaluate(getLinks);
console.log(links);
});
});
casper.run();
I really don't know what could cause this problem.