2016-08-18 16 views
-4

私はLive Cyber Atackからデータを取得します。私は、時間、攻撃、攻撃国、対象国を含むデータを取りたいと思います。私はこの動的なデータを取りたいです。分析後。私はJavaを使用しています。どのようにできるのか?Javaで動的HTMLページからデータを取得

<div ng-repeat="attack in latestAttacks" class="attackRow" "=""> 
      <div class="timeCol" inline-animation="{ properties: { opacity : 1 }, duration: 500, easing:'swing'}" style="opacity: 0.0254519;"> 
       <p> 
        14:40:22 
       </p> 
      </div> 
      <div class="attackCol" inline-animation="{ properties: { opacity : 1 }, duration: 500, easing:'swing'}" style="opacity: 0.0254519;"> 
       <p class="attackContainer"> 
        infecting website.cb 
       </p> 
      </div> 
      <div class="sourceCol" inline-animation="{ properties: { opacity : 1 }, duration: 500, easing:'swing'}" style="opacity: 0.0254519;"> 
       <p> 
        China 
       </p> 
      </div> 
      <div class="destCol" inline-animation="{ properties: { opacity : 1 }, duration: 500, easing:'swing'}" style="opacity: 0.0254519;"> 
       <p> 
        India 
       </p> 
      </div> 
     </div> 
+0

私は上記のコードを書いていません。私はちょうど取るべきデータの場所を示したかったのです。 – rdmzcn

答えて

1

あなたができることは、このウェブサイトのようなデータをWebSocket経由で取得することです。最初にWebSocketクライアントが必要です。ここではJSR 356 - Java API for WebSocketという参照実装を使用しています(Tyrus)。ここで、あなたはMavenを使用すると仮定すると

はのWebSocketクライアントのプロジェクトに追加するには依存関係がある:あなたが受け取る

<dependency> 
    <groupId>javax.websocket</groupId> 
    <artifactId>javax.websocket-api</artifactId> 
    <version>1.1</version> 
</dependency> 
<dependency> 
    <groupId>org.glassfish.tyrus.bundles</groupId> 
    <artifactId>tyrus-standalone-client</artifactId> 
    <version>1.13</version> 
</dependency> 

データはJSON形式であるので、あなたは、あなたのパーサーが必要になりますここでは、プロジェクトに

<dependency> 
    <groupId>org.json</groupId> 
    <artifactId>json</artifactId> 
    <version>20160810</version> 
</dependency> 

を追加する必要がありますコードはどのように見えるかです:

final ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build(); 
URI uri = new URI(
    "wss://threatmap.checkpoint.com/ThreatPortal/websocket" + 
    "?X-Atmosphere-tracking-id=0" + 
    "&X-Atmosphere-Framework=2.2.5-javascript" + 
    "&X-Atmosphere-Transport=websocket" + 
    "&X-Atmosphere-TrackMessageSize=true" + 
    "&Content-Type=application/json" + 
    "&X-atmo-protocol=true" 
); 
ClientManager client = ClientManager.createClient(); 
try (Session session = client.connectToServer(new Endpoint() { 

    @Override 
    public void onOpen(Session session, EndpointConfig config) { 
     session.addMessageHandler(new MessageHandler.Whole<String>() { 

      @Override 
      public void onMessage(String message) { 
       // The data is of type "number|JSON Object" 
       // so we remove everything before the JSON Object 
       message = message.substring(message.indexOf('|') + 1); 
       if (!message.startsWith("{")) { 
        // Not a JSON Object so we skip it 
        return; 
       } 
       // Parse the JSON Object 
       JSONObject jsonObject = new JSONObject(message); 
       if (jsonObject.has("attackname")) { 
        System.out.printf(
         "Time: %tT Attack: %-40s Attacking Country: %-20s Target Country: %-20s%n", 
         Calendar.getInstance(), jsonObject.getString("attackname"), 
         new Locale("", jsonObject.getString("sourcecountry")).getDisplayName(), 
         new Locale("", jsonObject.getString("destinationcountry")).getDisplayName() 
        ); 
       } 
      } 
     }); 
    } 
}, cec, uri)) { 
    CountDownLatch messageLatch = new CountDownLatch(1); 
    // Wait forever 
    messageLatch.await(); 
} 

出力:

Time: 14:53:06 Attack: Trojan-Downloader.Win32.Sohanad.B  Attacking Country: United States  Target Country: Panama    
Time: 14:53:06 Attack: Trojan-Downloader.Win32.Sohanad.B  Attacking Country: United States  Target Country: Panama    
Time: 14:53:06 Attack: Trojan-Downloader.Win32.Sohanad.B  Attacking Country: United States  Target Country: Panama    
Time: 14:53:06 Attack: Trojan-Downloader.Win32.Sohanad.B  Attacking Country: United States  Target Country: Panama    
Time: 14:53:07 Attack: Trojan-Downloader.Win32.Sohanad.B  Attacking Country: United States  Target Country: Panama    
Time: 14:53:07 Attack: Trojan-Downloader.Win32.Sohanad.B  Attacking Country: United States  Target Country: Panama    
Time: 14:53:07 Attack: Trojan-Downloader.Win32.Sohanad.B  Attacking Country: United States  Target Country: Panama    
Time: 14:53:07 Attack: REP.huvcru        Attacking Country: France    Target Country: Panama    
Time: 14:53:08 Attack: REP.huvcru        Attacking Country: France    Target Country: Panama 
+0

ニコラスにどうもありがとうございました。 – rdmzcn

+0

もう1つ質問できますか?私はこのサイトのデータを編集しませんでした。手伝って頂けますか? http://hp.ipviking.com/ – rdmzcn

+0

それは別の問題ですので、新しい質問を投稿してください。問題を混在させることはできません。事前に –

関連する問題