Puppeteer doesn't return page content on Ubuntu xenial (hosted with Scaleway)
I have been setting up a discord bot that can get facts about cats (don't bother worrying why) and to do this i'm getting the facts from a website that generates the random facts with js everytime someone visits. So to get this information I used puppeteer which works fine when its run through the Visual Studio Code terminal.
However, because I want this bot to constantly be running I bought a server that can keep the info for the bot and keep it running (this server is running Ubuntu Xenial). This is where the problems start. First of all I couldn't run puppeteer without args: ['--no-sandbox', '--disable-setuid-sandbox']. Although, this is a big security risk I just wanted to get something working so I settled. The problem is: this code still works in the Visual Studio terminal and I receive the page info but on the server a blank line is returned.
const ch = require("cheerio");
const pp = require("puppeteer");
const url = "http://www.animalplanet.com/pets/cat-facts/";
var randomFact;
// the below is a promise items will return out of sync
pp
.launch({headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'], ignoreHTTPSErrors: true, dumpio: false})
.then(function(browser) {
console.log("1");
return browser.newPage();
})
.then(function(page) {
console.log("2");
return page.goto(url).then(function() {
console.log("3");
return page.content().catch();
});
})
.then(function(html) {
randomFact = ch(".global-body-text.description", html).text();
console.log(ch(".global-body-text.description", html));
console.log("4");
console.log(randomFact);
})
.catch(function(err) {
console.log("Page not found (" + url + ")");
});
The above is the code I used. If there is anything I should be doing to make it work on the server please let me know.
node.js ubuntu puppeteer
add a comment |
I have been setting up a discord bot that can get facts about cats (don't bother worrying why) and to do this i'm getting the facts from a website that generates the random facts with js everytime someone visits. So to get this information I used puppeteer which works fine when its run through the Visual Studio Code terminal.
However, because I want this bot to constantly be running I bought a server that can keep the info for the bot and keep it running (this server is running Ubuntu Xenial). This is where the problems start. First of all I couldn't run puppeteer without args: ['--no-sandbox', '--disable-setuid-sandbox']. Although, this is a big security risk I just wanted to get something working so I settled. The problem is: this code still works in the Visual Studio terminal and I receive the page info but on the server a blank line is returned.
const ch = require("cheerio");
const pp = require("puppeteer");
const url = "http://www.animalplanet.com/pets/cat-facts/";
var randomFact;
// the below is a promise items will return out of sync
pp
.launch({headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'], ignoreHTTPSErrors: true, dumpio: false})
.then(function(browser) {
console.log("1");
return browser.newPage();
})
.then(function(page) {
console.log("2");
return page.goto(url).then(function() {
console.log("3");
return page.content().catch();
});
})
.then(function(html) {
randomFact = ch(".global-body-text.description", html).text();
console.log(ch(".global-body-text.description", html));
console.log("4");
console.log(randomFact);
})
.catch(function(err) {
console.log("Page not found (" + url + ")");
});
The above is the code I used. If there is anything I should be doing to make it work on the server please let me know.
node.js ubuntu puppeteer
add a comment |
I have been setting up a discord bot that can get facts about cats (don't bother worrying why) and to do this i'm getting the facts from a website that generates the random facts with js everytime someone visits. So to get this information I used puppeteer which works fine when its run through the Visual Studio Code terminal.
However, because I want this bot to constantly be running I bought a server that can keep the info for the bot and keep it running (this server is running Ubuntu Xenial). This is where the problems start. First of all I couldn't run puppeteer without args: ['--no-sandbox', '--disable-setuid-sandbox']. Although, this is a big security risk I just wanted to get something working so I settled. The problem is: this code still works in the Visual Studio terminal and I receive the page info but on the server a blank line is returned.
const ch = require("cheerio");
const pp = require("puppeteer");
const url = "http://www.animalplanet.com/pets/cat-facts/";
var randomFact;
// the below is a promise items will return out of sync
pp
.launch({headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'], ignoreHTTPSErrors: true, dumpio: false})
.then(function(browser) {
console.log("1");
return browser.newPage();
})
.then(function(page) {
console.log("2");
return page.goto(url).then(function() {
console.log("3");
return page.content().catch();
});
})
.then(function(html) {
randomFact = ch(".global-body-text.description", html).text();
console.log(ch(".global-body-text.description", html));
console.log("4");
console.log(randomFact);
})
.catch(function(err) {
console.log("Page not found (" + url + ")");
});
The above is the code I used. If there is anything I should be doing to make it work on the server please let me know.
node.js ubuntu puppeteer
I have been setting up a discord bot that can get facts about cats (don't bother worrying why) and to do this i'm getting the facts from a website that generates the random facts with js everytime someone visits. So to get this information I used puppeteer which works fine when its run through the Visual Studio Code terminal.
However, because I want this bot to constantly be running I bought a server that can keep the info for the bot and keep it running (this server is running Ubuntu Xenial). This is where the problems start. First of all I couldn't run puppeteer without args: ['--no-sandbox', '--disable-setuid-sandbox']. Although, this is a big security risk I just wanted to get something working so I settled. The problem is: this code still works in the Visual Studio terminal and I receive the page info but on the server a blank line is returned.
const ch = require("cheerio");
const pp = require("puppeteer");
const url = "http://www.animalplanet.com/pets/cat-facts/";
var randomFact;
// the below is a promise items will return out of sync
pp
.launch({headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'], ignoreHTTPSErrors: true, dumpio: false})
.then(function(browser) {
console.log("1");
return browser.newPage();
})
.then(function(page) {
console.log("2");
return page.goto(url).then(function() {
console.log("3");
return page.content().catch();
});
})
.then(function(html) {
randomFact = ch(".global-body-text.description", html).text();
console.log(ch(".global-body-text.description", html));
console.log("4");
console.log(randomFact);
})
.catch(function(err) {
console.log("Page not found (" + url + ")");
});
The above is the code I used. If there is anything I should be doing to make it work on the server please let me know.
node.js ubuntu puppeteer
node.js ubuntu puppeteer
asked Dec 28 '18 at 21:14
RavenRaven
84
84
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53964345%2fpuppeteer-doesnt-return-page-content-on-ubuntu-xenial-hosted-with-scaleway%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53964345%2fpuppeteer-doesnt-return-page-content-on-ubuntu-xenial-hosted-with-scaleway%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown