79221612

Date: 2024-11-25 04:13:17
Score: 0.5
Natty:
Report link

The issues was the website using Shift_JIS. So Use iconv-lite to convert response to UTF-8. Heres how:

import fetch from 'node-fetch';
import { JSDOM } from 'jsdom';
import pkg from 'iconv-lite'; // Import iconv-lite. 

fetch('hhttps://target-website.tld/bbs.cgi')
  .then(response => response.buffer()) // get the buffer instead getting text.
  .then(buffer => {
    // convert to utf-8
    const htmlString = pkg.decode(buffer, 'sjis');
    console.log(htmlString); // IT WORKS

    // some code
  })
  .catch(error => console.error('Error fetching HTML:', error));
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: もぐもぐぷりん