Web Driver and Tor execution in java

517 views Asked by At

I am able to connect to tor using Firefox driver, but i want to know if i can connect to tor using phantomjs or html-unit driver?

for pantomjs i tried the below code

    String[] phantomArgs = new  String[] {
        "--webdriver-loglevel=NONE",
        "--webdriver=localhost:9150"
    };

    DesiredCapabilities dcaps = new DesiredCapabilities();
    dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath());

    dcaps.setCapability( "phantomjs.cli.args", phantomArgs);
    WebDriver driver = new PhantomJSDriver(dcaps);

if not then is there similar free proxy server which i can use ?

1

There are 1 answers

0
Vicky On

Sorry of the late answer.I have not personally tried tor with phantomjs but i have always been an ardent user of tor with all major browsers.I think the issue here occurs because you have not set the proxy type ie)You can indicate SOCKS proxy configuration

--proxy-type=socks5

Because tor is a socks proxy and not an http proxy

ArrayList<String> phantom = new ArrayList<String>();
phantom.add("--proxy=localhost:9150");
phantom.add("--proxy-type=socks5");
DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantom);
driver = new PhantomJSDriver(capabilities);

Hope this helps you...If it is still not working kindly get back.