const puppeteer = require("puppeteer");
const enderecoDoSite =
"https://www.ingressorapido.com.br/event/30604-1/d/58317";
let scrape = async (user, pass) => {
const browser = await puppeteer.launch({
headless: false,
args: ["--no-sandbox", "--disable-setuid-sandbox"]
});
// const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto(enderecoDoSite);
await page.evaluate(() => {
document
.querySelectorAll(
".item.card.selectable.style-scope.event-offers > div > span"
)
.forEach(element => {
console.log("TCL: scrape -> element", element);
if (!element.innerText.indexOf("Pista")) {
console.log("TCL: scrape -> element", element);
element.click();
}
});
});
await page.waitForNavigation();
await page.evaluate(() => {
document
.querySelectorAll(
".items.style-scope.price-list > .item.card span.price-list"
)
.forEach(element => {
console.log("TCL: scrape -> element", element);
if (!element.innerText.indexOf("Inteira")) {
element.parentNode.parentNode.querySelectorAll(
"select#select > option"
)[1].selected = "selected";
}
});
console.log(
'TCL: scrape -> document.querySelectorAll(".app-button-0[type=positive]")',
document.querySelectorAll(".app-button-0[type=positive]")
);
document.querySelectorAll(".app-button-0[type=positive]")[4].click();
});
// await page.click(".app-button-0[type=positive]");
// await page.select(inteira, "2");
// await page.click("span.event-offers");
// await page.click('#profile-nav-item');
// const btnComprarID = await page.evaluate(() => {
// return document.querySelector('.box_botao > a').getAttribute(data-id);
// });
// browser.close()
// return result
};
function tasks() {
return new Promise((resolve, reject) => {
// setTimeout(resolve, 100);
setTimeout(() => {
scrape();
resolve();
}, 2000);
});
}
(async () => {
for (let i = 0; i < 5; i++) {
await tasks();
console.log("Abrindo mais uma janela do navegador n:" + i);
}
})();