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 o
I can either choose to scrape the HTML and save it in a file or get the current url
Of course the solution is very specific to this exact site, but then again it is quite normal when doing web scraping.
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;
};
});
var links = [];
// Better to scrpape .events__title as it contains data-href attribute
$("#events-betting").find(".events__title:contains(World cup)").each(function (i, item) {
var lastPartOfurl = item.getAttribute("data-href");
lastPartOfurl = lastPartOfurl.split("/");
links.push("https://m.1xbet.co.ke/en/line/Football/" + item.getAttribute("data-champ") + "-" + lastPartOfurl[1]+'/');
})
return links;
});
console.log(links);
});
The result:
https://m.1xbet.co.ke/en/line/Football/1536237-FIFA-World-Cup-2018/,https://m.1xbet.co.ke/en/line/Football/1204917-FIFA-World-Cup-2018-Winner/,https://m.1xbet.co.ke/en/line/Football/1518431-FIFA-World-Cup-2018-Special-bets/,https://m.1xbet.co.ke/en/line/Football/1706515-FIFA-World-Cup-2018-Teams-Statistics-Group-Stage/