phantomjs + express无法正常工作并出现错误

时间:2020-06-29 17:41:35

标签: javascript express phantomjs

这是我执行网页抓取的app.js:

var fs = require('fs');
var path=require('path');
const express = require('express');
var phantomjs = require('phantomjs')
const phantom = require('phantom');

server.post("/"  ,async (req,res) =>{
const instance = await phantom.create();
    const page = await instance.createPage();
await page.open('mytestwebsite.com', function(status) {
data = page.evaluate(function(){
a = document.getElementsByClassName("class1").innerText;
b = document.getElementsByClassName("class2").innerText;
return data= {
    a,
    b,
}
});
 console.log(data);
instance.exit();
});
});
我收到以下错误:

info: SyntaxError: Unexpected token ',' 
info:   undefined:7 in Function  
info:   phantomjs://code/index.js:315  
info:   :0 in parse  
info:   phantomjs://code/index.js:307 in read  

0 个答案:

没有答案