Skip to content

Instantly share code, notes, and snippets.

@Gbahdeyboh
Last active June 20, 2019 16:16
Show Gist options
  • Save Gbahdeyboh/3db36152378065ac674cf09d092f12f6 to your computer and use it in GitHub Desktop.
Save Gbahdeyboh/3db36152378065ac674cf09d092f12f6 to your computer and use it in GitHub Desktop.
This replicates the clicking issue.
const puppeteer = require("puppeteer");
const scraper = {
test: async () => {
let browser, page;
try {
browser = await puppeteer.launch({
headless: false,
args: ["--no-sandbox", "--disable-setuid-sandbox"]
});
page = await browser.newPage();
} catch (err) {
console.log(err);
}
try {
await page.goto("https://www.betking.com/sports/s/eventOdds/1-840-841-0-0,1-1107-1108-0-0,1-835-3775-0-0,", {
waitUntil: "domcontentloaded"
});
console.log("scraping, wait...");
} catch (err) {
console.log(err);
}
console.log("waiting....");
try {
await page.waitFor('.eventsWrapper');
} catch (err) {
console.log(err, err.response);
}
try {
const divsInRegionAreaContainer = await page.$$('.areaContainer.region .regionGroup > .regionAreas > div:first-child > .area:nth-child(5) div');
const oddsListData = [];
for (const div of divsInRegionAreaContainer) {
const html = await page.evaluate(el => el.innerHTML, div);
if (html === 'GG/NG') {
oddsListData.push(html);
await div.click();
page.waitFor(1000);
}
}
console.log(oddsListData);
} catch (err) {
console.log(err);
}
}
}
scraper.test();
@Gbahdeyboh
Copy link
Author

This logs an array with [ 'GG/NG', 'GG/NG', 'GG/NG' ] to the terminal and clicks just the last GG/NG div on the page. Scroll down to the last section(the seria A) section to see the clicked element highlighted in orange and the dynamic data already loaded once the process completes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment