我正在尝试在Render上运行我的服务器,我配置了docker文件,以便pupetter正常工作。但是当我在Render上部署代码时,我遇到了相关的错误。我该如何解决这个问题?我一直在增加,但没有工作。
async function getResults(lnk) {
const results = [];
const timeFrames = [1, 5, 15];
const browser = await puppeteer.launch({
headless: 'new',
args: [
"--disable-setuid-sandbox",
"--no-sandbox",
"--single-process",
"--no-zygote",
],
protocolTimeout: 240000,// 60 saniye olarak ayarlanmıştır
executablePath:
process.env.NODE_ENV === "production"
? process.env.PUPPETEER_EXECUTABLE_PATH
: puppeteer.executablePath(),
});
const page = await browser.newPage();
// await page.setDefaultNavigationTimeout(0);
for (const i of timeFrames) {
const page = await browser.newPage();
const url = `${lnk}?timeFrame=${i * 60}`;
console.log(`Getting: ${url}`);
await page.goto(url, { waitUntil: ["domcontentloaded"],timeout: 100000 });
await page.waitForSelector("section.forecast-box-graph .title",{timeout: 10000});
// await page.waitForSelector('h1.main-title.js-main-title');
const status = await page.$eval(
"section.forecast-box-graph .title",
(el) => el.textContent
);
const Bank_Name = await page.$eval("h1.main-title.js-main-title", (el) =>
el.textContent.trim()
);
results.push(status);
await page.close();
}
await browser.close();
results.push(lnk.split("/").pop().split("-").join(" "));
return results;
}
async function scrape() {
while(true){
for (const lnk of Link_Lst) {
const results = await getResults(lnk);
console.log("getting result:",results);
if(results.includes("Strong Sell")){
console.log("HERE");
if (Sell_) {
sendAlertToTG(`Alert for Bank ${results.slice(-1)} - "STRONG SELL"`);
Sell_ = false;
}
}
if(results.includes("Strong Buy")){
if (Buy_) {
sendAlertToTG(`Alert for Bank ${results.slice(-1)} - "STRONG BUY"`);
Buy_ = false;
}
}
}
console.log("\n\nWaiting for___10___Seconds");
waitBeforeNextIteration(10000);
}
}
function waitBeforeNextIteration(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
scrape();
这是我的dockerfile:
FROM ghcr.io/puppeteer/puppeteer:20.1.2
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome-stable
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm ci
COPY . .
CMD [ "node", "index.js" ]
下面是dumpio错误日志:
[21:40:0508/181117.410689:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:18 PM [21:46:0508/181118.422748:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:18 PM [21:46:0508/181118.423699:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:18 PM [21:40:0508/181118.455193:ERROR:bus.cc(399)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
May 8 09:11:18 PM [21:40:0508/181118.455257:ERROR:bus.cc(399)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
May 8 09:11:18 PM [21:21:0508/181118.604874:ERROR:system_network_context_manager.cc(765)] Cannot use V8 Proxy resolver in single process mode.
May 8 09:11:19 PM [21:40:0508/181119.040595:ERROR:bus.cc(399)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
May 8 09:11:19 PM [21:40:0508/181119.041267:ERROR:bus.cc(399)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
May 8 09:11:19 PM [21:21:0508/181119.042829:ERROR:system_network_context_manager.cc(765)] Cannot use V8 Proxy resolver in single process mode.
May 8 09:11:19 PM
May 8 09:11:19 PM DevTools listening on ws://127.0.0.1:36065/devtools/browser/534507b8-8bff-4967-907a-a39d4897f259
May 8 09:11:21 PM [21:93:0508/181121.222028:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:21 PM [21:93:0508/181121.222132:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:21 PM [21:93:0508/181121.222220:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:21 PM [21:93:0508/181121.222285:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:21 PM [21:93:0508/181121.222372:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:22 PM [0508/181122.090203:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
May 8 09:11:22 PM [0508/181122.090313:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
May 8 09:11:22 PM /usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:61
May 8 09:11:22 PM _Callback_error.set(this, new Errors_js_1.ProtocolError());
May 8 09:11:22 PM ^
May 8 09:11:22 PM
May 8 09:11:22 PM ProtocolError: Protocol error (Target.createTarget): Target closed
May 8 09:11:22 PM at new Callback (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:61:35)
May 8 09:11:22 PM at CallbackRegistry.create (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:106:26)
May 8 09:11:22 PM at Connection._rawSend (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:216:26)
May 8 09:11:22 PM at Connection.send (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:210:21)
May 8 09:11:22 PM at CDPBrowser._createPageInContext (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js:273:94)
May 8 09:11:22 PM at CDPBrowserContext.newPage (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js:541:78)
May 8 09:11:22 PM at CDPBrowser.newPage (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js:267:78)
May 8 09:11:22 PM at getResults (/usr/src/app/index.js:79:32)
May 8 09:11:22 PM at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
May 8 09:11:22 PM at async scrape (/usr/src/app/index.js:174:23)
May 8 09:11:22 PM
May 8 09:11:22 PM Node.js v18.16.0
我该如何解决这个问题?
1条答案
按热度按时间2fjabf4q1#
看看我对你的问题的回答,here,首先看到了那个,我已经发布了一个代码,可以完成你在这里提出的问题。
基本上,
headless:"new"
会在Render服务器上导致错误,尽管它在本地工作正常。