You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to fetch things from another website with horseman, and then use it in my own web. However, my own res.send always triggers before horseman has collected data.
var Horseman = require('node-horseman');
var express = require("express");
var app = express();
var ProfName = 'Stahl';
var URL = "http://www.bruinwalk.com/search/?q=" + ProfName;
function getProf(callback){
var result = {com:"default", rat:"default"};
var horseman = new Horseman();
horseman.open(URL)
.evaluate(function(selector){
var els = $(selector);
$.each(els, function(i, el) {
var event = document.createEvent('MouseEvent');
event.initEvent('click', true, true);
el.dispatchEvent(event);
});
}, 'h1:eq(3)')
.delay(1000)
.evaluate(function(selector){
var els = $(selector);
$.each(els, function(i, el) {
var event = document.createEvent('MouseEvent');
event.initEvent('click', true, true);
el.dispatchEvent(event);
});
}, "div:contains('COM SCI 31')")
.delay(1000)
.screenshot('test1.png')
.text('.metric')
.then(function(text){
result.com = text;
})
.text('.expand-area>p')
.then(function(text){
result.rat = text;
})
.close();
callback(result.rat,result.com);
}
app.get("/",function(req,res){
getProf(function(comments, rating){
console.log(comments);
console.log(rating);
res.send('success');
});
});
this gives me
default
default
The text was updated successfully, but these errors were encountered:
I'm trying to fetch things from another website with horseman, and then use it in my own web. However, my own res.send always triggers before horseman has collected data.
this gives me
The text was updated successfully, but these errors were encountered: