2017-07-16 22 views
0

私はイスラエルのポストウェブサイトからの出荷を追跡する必要がありますアンドロイドアプリを開発しています。彼らはapiを持っていないので、私は特定のリンクを設定してjsoupでHTMLを解析してウェブサイトを操作しようとしていますが、トラッキング情報が動的に読み込まれるため動作しません。私はセレンとjsoupを組み合わせてみましたが、私は誰もがこのタスクのための技術やアプローチを持っていないビルドエラーを取得しているので、それはアンドロイド環境で実装することができますか分からないのですか?私はとても感謝しています。 trying to capture the info in blue boxandroid web scraping dynamic content jsoup

enter image description here

答えて

1

は、次のURLからデータを取得することができます。 http://www.israelpost.co.il/itemtrace.nsf/trackandtraceNOHEJSON?openagent&lang=EN&itemcode=RR123445677IL

チェックこのJavaコード:

import com.google.gson.Gson; 
import com.google.gson.annotations.SerializedName; 
import org.jsoup.Connection; 
import org.jsoup.Jsoup; 
import org.jsoup.nodes.Document; 
import org.jsoup.nodes.Element; 
import org.jsoup.select.Elements; 

import java.io.IOException; 

public class IsraeliPost { 
    public static void main(String[] args) { 

     String URL = "http://www.israelpost.co.il/itemtrace.nsf/trackandtraceNOHEJSON?openagent&lang=EN&itemcode="; 
     String itemNumber = "RR123445677IL"; 

     try { 
      Connection.Response response = Jsoup.connect(URL + itemNumber) 
        .ignoreContentType(true) 
        .method(Connection.Method.GET) 
        .execute(); 

      String jsonResponse = response.body(); 
      ItemData itemData = new Gson().fromJson(jsonResponse, ItemData.class); 
      String itemCodeInfo = itemData.getItemcodeinfo(); 

      Document document = Jsoup.parse(itemCodeInfo); 

      Elements table = document.select("table").select("tbody"); 

      for (Element raw : table) { 
       Elements tds = raw.select("td"); 
       for (Element td : tds) { 
        System.out.println(td.text()); 

       } 
      } 

     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 

    public class ItemData { 

     @SerializedName("itemcodeinfo") 
     private String mItemcodeinfo; 

     public String getItemcodeinfo() { 
      return mItemcodeinfo; 
     } 
    } 
} 

出力:

を日付郵便局都市説明30/01/2015 Shikun Memshalti Nahariya 受取人の権限のある指定者に配信28/01/2015 Shikun Memshalti Nahariya への配達のために郵便局に到着しました27/01/2015 Jaffo Tel Aviv Yaffo郵送で受け取った 処理のために転送された

+0

あなたはちょうど私の日を保存しましたありがとう! –