猿问

nodejs怎么才能用爬虫爬取https网页?

最近在学习nodejs,在尝试写一个简单的爬虫,用http.get(url..)的形式,爬取'http://segmentfault.com/'的问题列表,但是,好像nodejs不支持htpps的网页?

报错如下:

Error: Protocol "https:" not supported. Expected "http:"

at new ClientRequest (_http_client.js:54:11)

at Object.exports.request (http.js:31:10)

at Object.exports.get (http.js:35:21)

at Object.<anonymous> (E:\1Javascript\node-study\bug\crawler.js:24:6)

at Module._compile (module.js:570:32)

at Object.Module._extensions..js (module.js:579:10)

at Module.load (module.js:487:32)

at tryModuleLoad (module.js:446:12)

at Function.Module._load (module.js:438:3)

at Module.runMain (module.js:604:10)


一只甜甜圈
浏览 2768回答 1
1回答

慕盖茨4494581

没有代码,不过我猜你用错了模块const http = require('http')const https = require('https')&nbsp; &nbsp; // https用这个
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答