【发布时间】:2020-08-09 12:30:04
【问题描述】:
操作系统:CentOS 8
NodeJS 版本:v14.5.0
NPM 版本:6.14.5
运行我的 NodeJS 程序时,它使用 WebdriverIO 从 Target 和 BestBuy 等网站提取产品信息,据我所知,它无法连接到 Selenium 服务器。它会抛出一个未处理的承诺拒绝警告,如下所示。
ECONNREFUSED 127.0.0.1:PORT
我已经安装了 Selenium 独立服务器、Chromedriver、WDIO-Standalone 和 WebdriverIO。我尝试在端口 4444 上运行 Selenium 独立服务器 jar,以及具有以下驱动程序功能。
function driver(url, proxy) {
return new Promise((resolve, reject) => {
remote({
runner: true,
outputDir: __dirname,
services: [
["selenium-standalone", {
logPath: "./selenium.out",
args: {
version: "4.0.0",
seleniumArgs: ["-host", "127.0.0.1", "-port", "4444"]
}
}]
],
capabilities: {
browserName: "chrome",
port: 4444,
proxy: {
proxyType: "manual",
httpProxy: proxy.host + ":" + proxy.port
},
"goog:chromeOptions": {
args: [
"--headless", "--disable-gpu",
"user-agent=" + new UserAgent().toString()
]
}
}
}).then((browser) => sync(() => {
browser.url(url);
const $ = cheerio.load(browser.getPageSource());
browser.deleteSession();
resolve($)
}));
});
}
我似乎无法找出错误的原因。你怎么看?
【问题讨论】:
标签: node.js selenium centos webdriver selenium-chromedriver