Created
October 30, 2021 20:01
-
-
Save fogrew/2c360924cb7ade58014a1be82a903fed to your computer and use it in GitHub Desktop.
Snippet for DetTools to extracting data about watched films and series from kinopoisk to CSV format
This file contains 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
(function () { | |
const $items = document.querySelectorAll('.profileFilmsList .item') | |
const films = [] | |
$items.forEach($item => | |
films.push({ | |
id: $item.querySelector('[mid]').attributes.mid.value, | |
type: $item.querySelector('.nameRus a').pathname.split("/")[1], | |
nameRus: $item.querySelector('.nameRus').innerText, | |
nameEng: $item.querySelector('.nameEng').innerText, | |
date: $item.querySelector('.date').innerText, | |
vote: $item.querySelector('.myVote')?.innerText || "0" | |
}) | |
) | |
const esc = value => value.replace(/"/g, "").trim() | |
const quote = value => value ? `"${value}"` : '' | |
const wrap = value => quote(value) | |
const swapDayWithMonth = value => value.replace(/(\d\d\.)(\d\d\.)(.+)/,"$2$1$3") | |
const iso = value => new Date(swapDayWithMonth(value)).toISOString() | |
const filters = { | |
id: wrap, | |
type: wrap, | |
nameRus: wrap, | |
nameEng: wrap, | |
date: iso, | |
vote: wrap | |
} | |
const isFirstPage = false | |
let csv = isFirstPage ? Object.keys(filters) : '' | |
films.forEach((film) => { | |
csv += ` | |
` | |
for(let property in film) { | |
let filter = filters[property] | |
let value = film[property] | |
csv += filter(value) + ',' | |
} | |
}) | |
console.log(csv) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment