Skip to content

Instantly share code, notes, and snippets.

@terjokhin
Created August 17, 2017 05:16
Show Gist options
  • Select an option

  • Save terjokhin/b4edd20919f7ae254f584f3c4b0e46a5 to your computer and use it in GitHub Desktop.

Select an option

Save terjokhin/b4edd20919f7ae254f584f3c4b0e46a5 to your computer and use it in GitHub Desktop.
Traffic checker for yandex
var casper = require('casper').create({logLevel: "error"});
var url = 'https://yandex.ru/maps/213/moscow/?rtext=55.707218%2C37.962004~55.753747%2C37.681371&rtt=auto&l=trf%2Ctrfe&mode=routes&ll=37.818532%2C55.741678&z=11';
casper.options.viewportSize = { width: 1920, height: 1080 };
casper.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36');
casper.start(url, function() {
casper.waitForSelector('.driving-route-view__route-title-primary', function() {
this.echo(this.evaluate(getSelectedItems));
});
});
function getSelectedItems() {
var raw = document.querySelectorAll('.driving-route-view__route-title-primary')[0].innerHTML;
var values = raw.replace(/ /g, '').split(' ');
var 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;
}
casper.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment