Skip to content

Instantly share code, notes, and snippets.

@daltonmenezes
Created March 31, 2020 04:00
Show Gist options
  • Save daltonmenezes/34012ec5d23d0071874d3da910d7226a to your computer and use it in GitHub Desktop.
Save daltonmenezes/34012ec5d23d0071874d3da910d7226a to your computer and use it in GitHub Desktop.
Scraping GitHub status servers with javascript
fetch('https://www.githubstatus.com/')
.then(res => res.text())
.then(text => {
const parser = new DOMParser()
const dom = parser.parseFromString(text, 'text/html')
const status = Array.from(
dom.querySelectorAll("div.component-inner-container.showcased span.component-status"),
el => {
const alias = {
'status-green': 'normal',
'status-yellow': 'degraded',
'status-orange': 'degraded',
'status-red': 'incident'
}
const status = el.parentElement.classList[1]
return alias[status]
}
)
const fields = {
operations: '',
apiRequests: '',
webhooks: '',
issuesPRsProjects: '',
actions: '',
packages: '',
pages: ''
}
return Object.keys(fields).reduce((acc, key, index) => {
return acc = {
...acc,
[key]: status[index]
}
}, {})
})
.then(console.log)
/*
{
operations: "normal"
apiRequests: "normal"
webhooks: "normal"
issuesPRsProjects: "normal"
actions: "normal"
packages: "normal"
pages: "normal"
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment