Last active
August 29, 2015 13:56
-
-
Save picasso250/8896652 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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