-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (36 loc) · 1.1 KB
/
index.js
File metadata and controls
43 lines (36 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const cheerio = require('cheerio')
const axios = require('axios')
function cleanupString(str) {
return str.replace("\n", '').trim()
}
function cleanupDate(str) {
return cleanupString(str).split("\n").map((e) => e.trim()).join(" ")
}
const organizerPageURL = 'https://www.eventbrite.it/o/torino-hacknight-9053329779'
async function getOrganizerEvents(url) {
let response
try {
response = await axios.get(url)
} catch(error) {
console.error(error)
return
}
const $ = cheerio.load(response.data)
const selector = "#live_events"
let events = []
$(".list-card-v2", selector).each((idx, e) => {
// console.log(e)
events.push({
title: cleanupString($('.list-card__title', $(e)).text()),
date: cleanupDate($('.list-card__date', $(e)).text()),
venue: cleanupString($('.list-card__venue', $(e)).text()),
imageURL: $('.list-card__image img').attr('src'),
url: $('a', $(e)).attr('href'),
eid: "eventbrite:" + $('a', $(e)).attr('data-eid'),
})
})
return events
}
getOrganizerEvents(organizerPageURL).then((events) => {
console.log(events)
})