fetch(`test.html`)
.then(res => res.blob()) //blobとして読み込みむ
.then(res => {
return new Promise(resolve => {
const reader = new FileReader();
reader.onload = () => { resolve(reader.result) };
reader.readAsText(res, 'euc-jp'); // 第2引数に、任意で文字エンコーディングを指定し、文字列として読み込む
});
}).then(res => {
const document = new DOMParser().parseFromString(res, 'text/html'); // HTMLDocument (Document) が返る
console.log(document.getElementById('id名').innerText);
});
一度 Blob として読み込み、文字コードを指定して文字列に変換し、そこから DOM に parse する
参考
FileReader.readAsText() - 文字列として読み込む
DOMParser
Fetch API で Shift_JIS の HTML をDOM として読み込む