import axios from "axios"; import cheerio from "cheerio"; import express from 'express'; import request from 'request-promise' import jschardet from 'jschardet' import iconv from 'iconv' import fs from 'fs' const Iconv = iconv.Iconv const app = express() app.get('/', (req, res) => { const url = "https://100mountain.tistory.com/117" request({ url: url, encoding: null, }) .then(anyToUtf8) .then((html) => { // fs.writeFileSync("test.txt", '\ufeff' + html, {encoding: 'utf8'}); let $ = cheerio.load(html, null, false); let places = [] $('div.tt_article_useless_p_margin').each(function () { console.log("title", $(this).find('p').text()) }); console.log("places", places) }) function anyToUtf8(str) { const { encoding } = jschardet.detect(str); const iconv = new Iconv(encoding, "utf-8//translit//ignore"); return iconv.convert(str).toString(); } }) app.listen(3001, () => { console.log('Server is listening on port 3001') })