2015-02-06 146 views
1
調用webdriver的Tor的

我需要的Tor的webdriver的實例能夠推出google.com在TOR硒,java代碼在Windows中,並能夠搜索目標字符串

我的代碼如下

String torPath = "..Installations\\Tor\\Tor Browser\\Browser\\firefox.exe"; 
String profilePath = "..Installations\\Tor\\TorBrowser\\Browser\\TorBrowser\\Data\\Browser\\profile.default"; 
FirefoxProfile profile = new FirefoxProfile(new File(profilePath)); 
FirefoxBinary binary = new FirefoxBinary(new File(torPath)); 
FirefoxDriver driver = new FirefoxDriver(binary, profile); 
driver.get("http://www.google.com"); 

這會導致一個空白的Tor瀏覽器頁面打開。它不會根據需要加載google.com。我知道,配置文件是有效的/兼容的,因爲我可以成功啓動瀏覽器並配置文件與:

binary.startProfile(profile, profilePath, "")); 

我已經看過類似的問題,但沒有得到滿意的答覆。

可以這樣做嗎?如果是,如何? 我正在尋找Java代碼。

回答

0
FirefoxDriver firefoxDriver; 
    File torProfileDir = new File("C:\\tor\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default"); 
    FirefoxBinary binary = new FirefoxBinary(new File("C:\\tor\\Tor Browser\\Browser\\firefox.exe"));//C:\tor\Tor Browser\Browser 
    FirefoxProfile torProfile = new FirefoxProfile(torProfileDir); 
    torProfile.setPreference("webdriver.load.strategy", "unstable"); 
    binary.startProfile(torProfile, torProfileDir); 

    FirefoxProfile profile = new FirefoxProfile(); 
    profile.setPreference("network.proxy.type", 1); 
    profile.setPreference("network.proxy.socks", "127.0.0.1"); 
    profile.setPreference("network.proxy.socks_port", 9150); 

使用此代碼