Download a file process by server, with HtmlUnit
See original GitHub issueHi every one: as ask in this stackoverflow topic: https://stackoverflow.com/questions/66573770/download-a-file-process-by-server-with-htmlunit, I open this “issue” to find a way to solve my problem with HTMLUnit. Thank a lot for all comments,
I want to automatize file conversion available at: https://www.gpsvisualizer.com/map_input?form=googleearth My problem is that, gpsvisualizer allow standalone conversion, but I have 500 files to convert. So I used hmtlUnit to automatize the process.
Thank to the following code, I am able to modify “select” such as:
"Output file type"
"Add DEM elevation data"
upload my file and get the url of the redirected html page where I can download the wanted file.
My problem, is that I do not find a way to download the file.
Does any one have suggestion ?
Thank, in advance.
Here is my code: ` WebClient webClient = new WebClient(); webClient.getOptions().setCssEnabled(false); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setRedirectEnabled(true);
//fetching the web page
String url = "https://www.gpsvisualizer.com/map_input?form=googleearth";
//String url = "https://www.reddit.com/r/scraping/";
HtmlPage page = webClient.getPage(url);
System.out.println(page.getUrl());
System.out.println(page.getTitleText());
//Select set .kml file
HtmlSelect selectFileType = (HtmlSelect) page.getElementByName("googleearth_zip");
System.out.println(selectFileType.getOption(0).asText());
//System.out.println(selectFileType.getOption(1).asText());
HtmlOption kmlFile = selectFileType.getOptionByText(".kml (uncompressed)");
System.out.println(kmlFile.asText());
selectFileType.setSelectedAttribute(kmlFile, true);
//Select add elevation on file
HtmlSelect selectelevation = (HtmlSelect) page.getElementByName("add_elevation");
System.out.println(selectelevation.getOption(4).asText());
HtmlOption europeSRTM1 = selectelevation.getOptionByText("NASA SRTM1 (30m res., NoAm, Europe, more)");
System.out.println(europeSRTM1.asText());
selectelevation.setSelectedAttribute(europeSRTM1, true);
//add file
HtmlForm myForm = page.getFormByName("main");
HtmlFileInput fileInput = myForm.getInputByName("uploaded_file_1");
fileInput.setValueAttribute("/media/Stock/Projets/Suratram/Ressources/Traces_WS/puissance/kml_files/01_douce-signoret.kml");
HtmlElement submitBtn = page.getElementByName("submitted");
//page google
HtmlPage page2 = submitBtn.click();
System.out.println(page2.getUrl());
`
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (5 by maintainers)
Top GitHub Comments
Your welcome, have fun using HtmlUnit and please update the stackoverflow question
can you please provide a sample file and i will try to build a working sample for you