Big5 to utf-8 encoding while scraping website with Node-request

前端 未结 2 443
北海茫月
北海茫月 2021-02-06 11:02

I am new to Node.js, and I am trying to use the request model to scrap a website, I am having problem with the encoding: the target website is using big5 as encoding, and I wish

2条回答
  •  伪装坚强ぢ
    2021-02-06 11:45

    Might I suggest my codepage library:

    var request = require('request'), codepage = require('codepage')
    request({ url: 'http://amis.afa.gov.tw/v-asp/v101r.asp',encoding:null}, function(err,     response, body) {
      if (!err && response.statusCode == 200) {
        var str = codepage.utils.decode(950, new Buffer(body));
        console.log(str);
      }
    });
    

    yields

    ... 

    請使用瀏覽器工具列中[上一頁]回到前一輸入條件畫面繼續查詢

提交回复
热议问题