I'm using jQuery to get a list of elements that contain certain key words. I'm able to get the list of elements but I don't know how to loop through each element, click on its child element and download the newly loaded page. Here's the casperjs code I have so far:
var casper = require('casper').create({
clientScripts: ["/var/www/html/project/public/js/jquery-3.3.1.min.js"]
});
var fs = require('fs');
casper.start('https://m.1xbet.co.ke/en/line/Football/', function () {
var links = casper.evaluate(function () {
$.expr[":"].contains = $.expr.createPseudo(function (arg) {
return function (elem) {
return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
};
});
return $("#events-betting").find("li.events__item_head:contains(World cup)");
});
var date = new Date(), year = date.getFullYear(), month = date.getMonth() + 1, day = date.getDate();
var folderName = year + '-' + month + '-' + day;
// loop would go here to save each file
var path = "destination/" + folderName + "/1xbet/worldcup-1";
fs.write(path + ".html", this.getHTML(), "w");
});
casper.run();
I'd like to click on the individual items on the links object - they aren't anchor tags but rather they are clickable divs with inline javascript listening for a click.
The goal is to click on the div that has certain text I'm interested in, then once clicked, I can either choose to scrape the HTML and save it in a file or get the current url; either will be fine for my purposes. Since there could be multiple divs with the desired text, I'd like for a way to loop through each and do perform the same operation.
This is an example of the page I'm interested in:
https://m.1xbet.co.ke/en/line/Football/
The parent element in this case is: #events-betting and nested is a list of li tags with clickable divs.