nodejs爬虫--superagent结果出错

// https://s.hc360.com/?w= + keyword
//在拼接网址字符串时,需要对关键字进行encodeURIComponent()编码处理,否则中文字会出现乱码。

const superagent = require('superagent');

const charset = require('superagent-charset');



charset(superagent);

superagent.get('https://s.hc360.com/?w=轮毂拉丝机')
    .charset('gb2312')

    

    .end((err,res)=>{

        if(err)

            return console.log('爬取失败');

        console.log(res.text);

    })

这段代码无法输出正确的结果,有人知道代码哪里出错了吗?
谢谢啦

阅读 3.8k
1 个回答

clipboard.png

// https://s.hc360.com/?w= + keyword
//在拼接网址字符串时,需要对关键字进行encodeURIComponent()编码处理,否则中文字会出现乱码。
const superagent = require('superagent');
const charset = require('superagent-charset');
charset(superagent);
superagent.get('https://s.hc360.com/?w=轮毂拉丝机')
    .charset('gb2312')
    .end((err, res) => {
        if (err) return console.log('爬取失败');
        console.log(res.text);
    })

能够获取到目标网页结果

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题