Skip to content

Instantly share code, notes, and snippets.

@andreasasprou
Created August 15, 2017 16:53
Show Gist options
  • Save andreasasprou/eeb9b9bf83b6320f250639f709c34df6 to your computer and use it in GitHub Desktop.
Save andreasasprou/eeb9b9bf83b6320f250639f709c34df6 to your computer and use it in GitHub Desktop.
require('chromedriver');
const webdriver = require('selenium-webdriver');
const cheerio = require('cheerio');
const Builder = webdriver.Builder
const By = webdriver.By
const until = webdriver.until
const driver = new Builder()
.setAlertBehavior('ignore')
.forBrowser('chrome')
.build();
main(driver)
async function openAllMarketGroups(driver) {
await driver.wait(until.elementLocated(By.css('.gl-MarketGroup')), 3000)
const groups = await driver.findElements(By.css('.gl-MarketGroup'))
for (let i = 0; i < groups.length; i++) {
const group = groups[i];
try {
await group.findElement(By.css('.gl-MarketGroup_Wrapper'))
} catch(error) {
try {
await group.findElement(By.css('.gl-MarketGroupButton')).click()
} catch (error) {}
}
}
}
async function main(driver) {
await driver.get('https://www.bet365.com')
await driver.findElement(By.id('TopPromotionButton')).click();
await driver.wait(until.elementLocated(By.xpath("//div[text() = 'In-Play']")), 1000);
await driver.findElement(By.xpath("//*[text() = 'In-Play']")).click();
// await driver.wait(until.elementLocated(By.css('.sm-LiveInPlayHeader_Container')));
// await driver.findElement(By.css('.sm-LiveInPlayHeader_Container')).click();
await driver.wait(until.elementLocated(By.css('.ipo-Fixture_ScoreDisplay')), 3000);
const links = await driver.findElements(By.css('.ipo-Fixture_ScoreDisplay'));
const fixtureDetails = []
for (let i = 0; i < links.length; i++) {
const newLinks = await driver.findElements(By.css('.ipo-Fixture_ScoreDisplay'));
const fixtureDetail = await getFixtureDetials(driver, newLinks[i])
console.log(fixtureDetail)
fixtureDetails.push(fixtureDetail)
}
console.log(fixtureDetails)
fs.writeFile('data.json', JSON.stringify(fixtureDetails), (res) => {
console.log("done");
});
// await driver.quit()
}
async function getFixtureDetials(driver, link) {
await link.click();
await openAllMarketGroups(driver)
const pageHtml = await driver.getPageSource();
const $ = cheerio.load(pageHtml)
const time = $('.ipe-SoccerHeaderLayout_ExtraData').text()
const teamNames = $('.ipe-SoccerGridColumn_TeamName').map((i, el) => $(el).text()).get()
const corners = {
home: $('.ipe-SoccerGridColumn_ICorner .ipe-SoccerGridCell').eq(0).text(),
away: $('.ipe-SoccerGridColumn_ICorner .ipe-SoccerGridCell').eq(1).text()
}
const goals = {
home: $('.ipe-SoccerGridColumn_IGoal .ipe-SoccerGridCell').eq(0).text(),
away: $('.ipe-SoccerGridColumn_IGoal .ipe-SoccerGridCell').eq(1).text()
}
const marketGroups = $('.gl-MarketGroup').map(function (index, elem) {
return {
title: $(this).find('.gl-MarketGroupButton_Text').text(),
odds: $(this).find('.gl-Participant').map(function (index, elem) {
return {
title: $(this).find('.gl-Participant_Name').text(),
value: $(this).find('.gl-Participant_Odds').text()
}
}).get()
};
}).get()
await driver.findElement(By.xpath("//*[text() = 'Overview']")).click();
return {
time,
teamNames,
corners,
goals,
marketGroups,
}
}
const exampleData = [{
time: 'number',
fullTime: [
{
home: {
name: 'string',
odds: 'number',
},
away: {
name: 'string',
odds: 'number',
},
draw: 'number',
}
]
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment