0

How I can parse the response of this request using JSOUP, I need to get data frome the table, when I look in source code I found just a static html, but how I can get data ?

EDIT :

ArrayList<String> downServers = new ArrayList<>();
    Date date = new Date();
      url = "http://billetterie.ctm.ma/site/get_voyages?nat=1&tov1=nat&aller=AS&ag_dep=001&ag_arr=002&datev=29-05-2016&dater=29-05-2016&nbp=1&tpay=MA&horr=non";
    String URL1 = "http://billetterie.ctm.ma/site/select_voyages_aller?datev=29-05-2016&agen_dep=001&agen_dest=002&nbp=1&dater=29-05-2016&aller=AS&tpay=MA&q=1&_search=false&nd="+date.getTime()+"&rows=30&page=1&sidx=&sord=";

    Document doc = null;
    try {
        response = Jsoup.connect(url).timeout(10000).method(Connection.Method.GET).execute();
        Map<String, String> cookies = response.cookies();
        doc = Jsoup.connect(URL1).timeout(10000).cookies(cookies).get();
        ;
    } catch (IOException e) {
        e.printStackTrace();
    }
NizarETH
  • 969
  • 3
  • 15
  • 38

1 Answers1

0
  1. Send a GET request to MainPage. The response contains cookies - save it. Also remember to use the user agent string of your browser, so you will get the same response as the browser does.
  2. Send a GET request to http://billetterie.ctm.ma/site/select_voyages_aller with the cookies from stage 1 and all the parameters -

    datev=26-05-2016
    agen_dep=001
    agen_dest=002
    nbp=1
    dater=26-05-2016
    aller=AS
    tpay=MA
    q=1
    _search=false
    nd=1464315650186
    rows=30
    page=1
    sidx=
    sord=

You'll have to figure the meaning of each parameter and chang it according to your needs. This wil get you the first table.

  1. For the second table, send a GET request to http://billetterie.ctm.ma/site/select_poar_aller with the cookies and the following parameters -

    datev=26-05-2016
    agen_dep=001
    agen_dest=002
    nbp=1
    dater=26-05-2016
    aller=AS
    q=1
    _search=false
    nd=1464315650212
    rows=30
    page=1
    sidx=
    sord=

How do I know it? Open your browser's developer tools (F12) and watch the network traffic - You'll see 3 GET requests. The first request gives you the seesion cookie (it also gives you the page itself, but you don't need it) and the other two contain the tables.

TDG
  • 5,909
  • 3
  • 30
  • 51
  • Hi, thank's for the help, you 're right, I cheek what did you say I found a json like response in network of navigator. – NizarETH May 27 '16 at 19:48
  • I don't know where I can find this parameter: **nd = XXXXXXXXXX**, I look in the cookie and the header of response but it's not there, so can u please take a look ? – NizarETH May 27 '16 at 22:12
  • The `nd` is unix time stamp (in milliseconds). You can find many online converters, like this - http://www.epochconverter.com/ or do it yourself in Java - http://stackoverflow.com/questions/7784421/getting-unix-timestamp-from-date – TDG May 28 '16 at 07:06
  • Thank you, you are the best ! – NizarETH May 28 '16 at 11:07
  • Hi sorry for distrurbing you, I did as you say stage 1, I get the coockie and I send the second request with the cookie and the given url with parametre but the result is coode 500, even I try the url in my navigator it doesn't work, I add edit in my post, could you please cheek ? – NizarETH May 28 '16 at 15:05