--- miscJava/SpejdernetScraper/src/dk/thoerup/spejdernetscraper/ScraperWorker.java 2013/11/14 13:18:10 2071 +++ miscJava/SpejdernetScraper/src/dk/thoerup/spejdernetscraper/ScraperWorker.java 2013/11/15 07:59:04 2072 @@ -15,18 +15,18 @@ @Override public void run() { - long start = System.currentTimeMillis(); + ResultBuffer rb = ResultBuffer.getResultBuffer(); try { rb.clear(); - rb.addString(start, "Starting"); + rb.addString("Starting"); Response res = Jsoup.connect("http://medlemssystem.spejdernet.dk/login.aspx?ReturnUrl=%2f").execute(); Map cookies = res.cookies(); - rb.addString(start, "Got login page"); + rb.addString("Got login page"); res = Jsoup .connect("http://medlemssystem.spejdernet.dk/Login.aspx?changeuser=1") @@ -42,7 +42,7 @@ .cookies(cookies) .execute(); - rb.addString(start, "Login OK"); + rb.addString("Login OK"); //This will get you cookies cookies.putAll( res.cookies() ); //printMap(cookies); @@ -52,20 +52,20 @@ //And this is the easieste way I've found to remain in session Response data = Jsoup.connect(dataCsvUrl).cookies(cookies).timeout(10000).execute(); if ( ! data.contentType().equalsIgnoreCase("text/x-csv; charset=iso-8859-1") ) { - rb.addString(start, "Data.csv - has the wrong content type: " + data.contentType()); + rb.addString("Data.csv - has the wrong content type: " + data.contentType()); return; } String dataCsv = data.body(); - rb.addString(start, "Got data.csv"); + rb.addString("Got data.csv"); String rollerCsvUrl = "http://medlemssystem.spejdernet.dk/DataExport.aspx?Id=5c0cf638-dc87-413f-91b6-9c7300c70137&listid=e8c5ae9d-5ea7-4a00-bea4-a0ce00ea891e&execute=true"; Response roller = Jsoup.connect(rollerCsvUrl).cookies(cookies).timeout(10000).execute(); if ( ! roller.contentType().equalsIgnoreCase("text/x-csv; charset=iso-8859-1") ) { - rb.addString(start, "Roller.csv - has the wrong content type: " + roller.contentType()); + rb.addString("Roller.csv - has the wrong content type: " + roller.contentType()); return; } String rollerCsv = roller.body(); - rb.addString(start, "Got roller.csv"); + rb.addString("Got roller.csv"); Map postData = new TreeMap(); postData.put("roller", rollerCsv); @@ -75,12 +75,12 @@ byte resp[] = HttpUtil.postContent("http://horsensspejder.t-hoerup.dk/data/postdata.php", params, 3000); String response = new String(resp); - rb.addString(start, "POST Response: " + response); + rb.addString("POST Response: " + response); - rb.addString(start, "Done !"); + rb.addString("Done !"); } catch (Exception e) { - rb.addString(start, "Error occurred: " + e.toString() ); + rb.addString("Error occurred: " + e.toString() ); } }