做爬虫时,偶尔会爬到这样的内容天堂向左,如何转为中文?

  node.js, question

I want to know about coding, do you have any good books to recommend, thank you! !

Thank you for your answers. According to the prompts, I wrote a program test myself. OK, is there anything else?

var code10, code16, zh;

code10 = '天堂向左,深圳向右';

zh = code10.replace(/&#(\d加);/g, function($, $1) {return String.fromCharCode($1)});

console.log(zh);

code16 = zh.replace(/[^\u0000-\u00ff]/g, function($) {return '&#x' 加 $.codePointAt(0).toString(16) 加 ';';});

console.log(code16);

zh = code16.replace(/&#x(\w加);/g, function($, $1) {return String.fromCharCode(parseInt($1, 16))});

console.log(zh);

The beginning is Decimal coding, but when converting to Chinese, it should be noted that Chinese is multi-character coding. Functions that can use javascript

String.fromCharCode(str.substr(2),10)

Cooperate with the loop to write a small tool to handle before climbing at the front end, such as ` String.fromCharCode (“day”. substr(2),10)
Get “heaven”.
Today I just wrote a little tool.

https://github.com/hunnble/JavaScript_learning/blob/master/change-radix.html

Open it in the browser and enter the character you want to transcode, then select decimal to 10 and decode it.