这是我的 test.js 脚本代码:
require('geckodriver');
const config = require("../config/config.json");
var webDriver = require("selenium-webdriver");
var firefox = require("selenium-webdriver/firefox");
var proxy = require("selenium-webdriver/proxy");
var options = new firefox.Options();
options.addArguments("-headless");
var driverFirefox = new webDriver.Builder()
.withCapabilities(webDriver.Capabilities.firefox())
.setProxy(proxy.socks('username:password@proxy_host:port'))
.setFirefoxOptions(options)
.build();
call1() {
try {
driverFirefox
.wait(driverFirefox.get('http://IP_Address:PORT'))
.then(function() {
console.log("Success!!!!");
});
} catch (mainError) {
console.log("Inside try's catch block");
console.log(mainError);
}
}
call1();
在运行脚本test.js时使用上述代码,我在请求的URL(http://IP_Address:PORT)中获取了请求的公共IP地址,而不是代理IP地址。
以下是http://IP_Address:PORT路线中用于打印请求IP的代码:
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log('IP: ', ip);
有人可以建议我如何在脚本中获取代理IP吗?