Skip to content

Instantly share code, notes, and snippets.

@picasso250
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save picasso250/8896652 to your computer and use it in GitHub Desktop.
Save picasso250/8896652 to your computer and use it in GitHub Desktop.
var request = require('request');
var cheerio = require('cheerio');
var Iconv = require('iconv').Iconv;
var iconv = require('iconv-lite');
var i = 10;
var url = 'http://www.esgweb.net/Html/Yxzcpstj/'+i+'.htm';
console.log(url);
request(url, function(err, resp, body) {
if (err)
throw err;
// did not work
$ = cheerio.load(iconv.decode(body, 'gbk'));
console.log($('body').text());
// did not work either
var converter = new Iconv('GB2312', 'UTF-8');
var utf8_buffer = converter.convert((body));
console.log(utf8_buffer.toString());
});
<?php
// it works!
$ch = curl_init('http://www.esgweb.net/Html/Yxzcpstj/10.htm');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$body = curl_exec($ch);
echo($body);
echo iconv('gbk', 'utf8', $body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment