2016-08-15 59 views
-1

我正在嘗試使用phantomjs爲https://www.google.com捕獲簡單屏幕截圖。屏幕截圖顯示爲空白。我在windows和jar中使用eclipse phantomjsdriver1.1,硒罐所有2.39版本。phantomjs無法從https網站捕獲屏幕截圖

當我提到網站爲http://google時,它會重定向到https並捕獲屏幕截圖。但我需要它僅以https進行捕獲。以下是我的代碼。提前致謝 。

import java.io.File; 
import java.io.IOException; 
import java.util.concurrent.TimeUnit; 

import net.anthavio.phanbedder.Phanbedder; 

import org.apache.commons.io.FileUtils; 
import org.openqa.selenium.OutputType; 
import org.openqa.selenium.TakesScreenshot; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.phantomjs.PhantomJSDriver; 
import org.openqa.selenium.phantomjs.PhantomJSDriverService; 
import org.openqa.selenium.remote.DesiredCapabilities; 

public class Schedule { 

    public static void main(String[] args) { 
     File phantomjs = Phanbedder.unpack(); 

     DesiredCapabilities dcaps = new DesiredCapabilities(); 

     dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath()); 
     dcaps.setCapability("takesScreenshot", true); 
     String [] phantomJsArgs = {"---ignore-ssl-errors=yes"}; 
     dcaps.setCapability(
       PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS, 
       phantomJsArgs); 

     PhantomJSDriver driver = new PhantomJSDriver(dcaps); 
     driver.get("https://www.google.com"); 


     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

     File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); 
     try { 
     FileUtils.copyFile(scrFile, new File("C:\\Users\\Desktop\\fci\\sample.jpeg"),true); 

     } catch (IOException e) { 
      System.out.println("exception"); 
     } 

     System.out.println("Page title is: " + driver.getTitle()); 

     driver.quit(); 
    } 
} 
+0

您使用哪個PhantomJS版本?我的意思是可執行版本而不是驅動程序版本。 –

+0

我正在使用phanbedder-1.9.7-1.0.0.jar。這個jar裏面有exe文件 - phantomjs.exe – dan

+0

這是exe的版本phantomjs \ AppData \ Local \ Temp \ phantomjs-1.9.7 \ phantomjs.exe – dan

回答

0

PhantomJS是一款無頭瀏覽器的含義;你不會看到發生了什麼;所做的一切都是在後臺完成的。