var request = require('request');
var cheerio = require('cheerio');

var url = 'https://www.list.co.uk/events/days-out/when:this%20weekend/location:Dumbarton(55.9460,-4.5556)/distance:20/';


var j=[];


request(url, function(err, resp, body) {
    if (err)
        throw err;
    $ = cheerio.load(body);
    console.log($);
    // TODO: scraping goes here!

    $('.resultsRow').each( function(div)
    {
        var item={};
        var eventSummary = $(this).find('.eventSummary').first();
        var byDate = $(this).find('.byDate').first();

        var title = eventSummary.find('.head').first();
        var description = eventSummary.find('P').first();
        var link = ' https://www.list.co.uk' + eventSummary.find('A').first().attr('href');

        var price = byDate.find('.price').first();
        var dt = byDate.find('.dtstart').first().attr('title');
        console.log('+++');
       // console.log($(this).html());
        console.log('###');
        console.log(description.text());
        console.log(link);
        console.log('---');

        item.title = title.text();
        item.description = description.text();
        item.link = link;
        item.price = price.text();
        item.date = dt;

        j.push(item);
    });

    console.log(j);
});

/*

 https://www.list.co.uk/event/351218-pollock-parkrun/

<div class="eventSummary clearfix noImage">
    <a href="/event/351218-pollock-parkrun/">
    <h2 class="head">Pollock parkrun</h2>
</a>
<p>An informal weekly 5k run in Pollok Country Park. Everyone is welcome, no matter how fast or slow (you&apos;re welcome to walk the route, bring your dog or push a buggy), so you can use it as a one-off fitness test, a chance to get some fresh air or come every week to try to beat your personal best time. It&apos;s friendly and&#x2026;</p>
</div>*/
