2016-06-09 3 views
1

나는 firefox 브라우저에서 har 데이터를 가져 오기위한 클래스를 작성했습니다.json 및 문자열 형식으로 Har 데이터 가져 오기

har 데이터를 JSON 형식으로 올바르게 표시하고자합니다.

내 코드 :

ProxyServer server = new ProxyServer(4444); 
    server.start(); 

    //captures the moouse movements and navigations 
    server.setCaptureHeaders(true); 
    server.setCaptureContent(true); 

    // get the Selenium proxy object 
    Proxy proxy = server.seleniumProxy(); 

    // configure it as a desired capability 
    DesiredCapabilities capabilities = new DesiredCapabilities(); 
    capabilities.setCapability(CapabilityType.PROXY, proxy); 

    // start the browser up 
    WebDriver driver = new FirefoxDriver(capabilities); 

    // create a new HAR with the label "apple.com" 
    server.newHar("yahoo.com"); 

    // open yahoo.com 
    driver.get("http://yahoo.com"); 

    // get the HAR data 
    net.lightbody.bmp.core.har.Har har = server.getHar(); 

월 누군가가 JSON 형식으로 너무 문자열의 HAR의 데이터를 가져 오는 저를 도와주세요!

답변

1

늦게 답변드립니다.

다른 사람을 도울 수 있기를 바랍니다.

StringWriter를 사용하여 Har에서 String으로 작성할 수 있습니다. 그래서 har를 문자열로 가져올 수 있습니다. 그리고 Gson을 사용하여 해당 문자열을 구문 분석하여 JSON 객체를 가져올 수 있습니다.

net.lightbody.bmp.core.har.Har har = server.getHar(); 

java.io.StringWriter writer = new java.io.StringWriter(); 
try { 
      har.writeTo(writer); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

String harAsString = writer.toString(); 

com.google.gson.JsonElement harAsJson = new com.google.gson.Gson().toJsonTree(writer.toString()); 
관련 문제