Last active
August 30, 2018 13:21
-
-
Save terjokhin/507715153091740ff812c774ff6dedb2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require('puppeteer'); | |
let scrape = async () => { | |
const browser = await puppeteer.launch({headless: false}); | |
const page = await browser.newPage(); | |
await page.goto('https://yandex.ru/maps/213/moscow/?ll=37.820579%2C55.730541&z=12&mode=routes&rtext=55.707218%2C37.962004~55.753747%2C37.681371&rtt=auto'); | |
await page.waitFor(3000); | |
const raw = await page.evaluate(() => { | |
let rawTime = document.querySelector('#sidebar-container > div > div > div.sidebar-panel-view__content > div > div > div.scroll > div > div.scroll__content > div > div.route-panel-content-view__top-content > div.route-panel-content-view__route-list > div > div.route-list-view__list > div > div > div.driving-route-view__route-title > div.driving-route-view__route-title-primary').innerText; | |
let values = rawTime.replace(/ /g, '').split(' '); | |
let result; | |
if (values.length == 1) { | |
result = parseInt(values[0].replace(/[^0-9]/g,'')); | |
} else if (values.length == 2) { | |
var hours = parseInt(values[0].replace(/[^0-9]/g,'')); | |
var mins = parseInt(values[1].replace(/[^0-9]/g,'')); | |
result = hours * 60 + mins; | |
} else { | |
result = -1; | |
} | |
return { | |
result | |
} | |
}); | |
browser.close(); | |
return raw; | |
}; | |
scrape().then((value) => { | |
console.log(value.result); // Success! | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment