Last active
May 17, 2023 03:07
-
-
Save GitHub30/14c669107d3e341018e89443d0f86635 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const days = 365 | |
const urls = ['', ...[...Array(days).keys()].map(i=>i+1).map(i=>new Date(Date.now() - 1000*60*60*24*i).toLocaleDateString('sv').replaceAll('-', '')).map(d => '/' + d)].map(path => 'https://b.hatena.ne.jp/hotentry/it' + path) | |
const htmls = await Promise.all(urls.map(url => fetch(url).then(r=>r.text()))) | |
const docs = htmls.map(html => new DOMParser().parseFromString(html,'text/html')) | |
function countAndSort(arr) { | |
return Object.entries(arr.reduce((prev, curr) => (prev[curr] = ++prev[curr] || 1, prev), {})).sort((a,b) => b[1]-a[1]) | |
} | |
countAndSort(docs.flatMap(doc => [...doc.querySelectorAll('.entrylist-contents-domain>a>span')].map(s => s.textContent))) | |
blog_domains = [ | |
"hatenadiary.jp", | |
"hatenablog.com", | |
"hateblo.jp", | |
"hatenablog.jp", | |
"hatenadiary.com" | |
] | |
countAndSort(docs.flatMap(doc => [...doc.querySelectorAll('.entrylist-contents-domain>a>span')].map(s => s.textContent.toLowerCase())).filter(d => blog_domains.some(bd => d.endsWith(bd))).map(d => blog_domains.find(bd => d.endsWith(bd)))) | |
[ | |
[ | |
"hatenablog.com", | |
594 | |
], | |
[ | |
"hatenablog.jp", | |
73 | |
], | |
[ | |
"hatenadiary.jp", | |
49 | |
], | |
[ | |
"hateblo.jp", | |
43 | |
], | |
[ | |
"hatenadiary.com", | |
8 | |
] | |
] | |
blog_domains = [ | |
"hatenadiary.jp", | |
"hatenablog.com", | |
"hateblo.jp", | |
"hatenablog.jp", | |
"hatenadiary.com", | |
"impress.co.jp", | |
"itmedia.co.jp" | |
] | |
countAndSort(docs.flatMap(doc => [...doc.querySelectorAll('.entrylist-contents-domain>a>span')].map(s => s.textContent.toLowerCase().split('/')[0])).map(d => blog_domains.some(bd => d.endsWith(bd)) ? blog_domains.find(bd => d.endsWith(bd)) : d)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment