Node.js PhantomJS和NodeJS中的请求在特定网页中不起作用
我正在尝试使用NodeJS上的幻影从一个站点获取信息。我的代码如下:Node.js PhantomJS和NodeJS中的请求在特定网页中不起作用,node.js,phantomjs,Node.js,Phantomjs,我正在尝试使用NodeJS上的幻影从一个站点获取信息。我的代码如下: const phantom = require('phantom'); const instance = await phantom.create(['--local-url-access=false', '--ssl-protocol=any']); const page = await instance.createPage(); await page.on('onResourceRequested', functio
const phantom = require('phantom');
const instance = await phantom.create(['--local-url-access=false', '--ssl-protocol=any']);
const page = await instance.createPage();
await page.on('onResourceRequested', function(requestData) {
console.info('Requesting', requestData.url);
});
page.open('https://www.google.com/').then(async (status) => {
await instance.exit();
resolve(null);
}).catch((err) => {
reject(err);
});
它工作没有问题,但是当我把urlhttps://reclameaqui.com.br 不加载内容当我在API中使用此代码时,它工作正常
var express = require("express");
var router = express.Router();
const phantom = require("phantom");
/* GET home page. */
router.get("/", async function(req, res, next) {
res.render("index", { title: "Express" });
const instance = await phantom.create([
"--local-url-access=false",
"--ssl-protocol=any"
]);
const page = await instance.createPage();
await page.on("onResourceRequested", function(requestData) {
// console.info("Requesting", requestData.url);
console.log(requestData);
});
page
.open("https://reclameaqui.com.br/")
.then(async status => {
await instance.exit();
resolve(null);
})
.catch(err => {
reject(err);
});
});
module.exports = router;
感谢您的帮助,但在本例中,代码不返回状态响应数据,只返回请求。如果您尝试.thenasync status=>{console.logstatus;};这不管用