question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Download a file process by server, with HtmlUnit

See original GitHub issue

Hi 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:closed
  • Created 2 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rbricommented, May 19, 2021

Your welcome, have fun using HtmlUnit and please update the stackoverflow question

1reaction
rbricommented, May 14, 2021

can you please provide a sample file and i will try to build a working sample for you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Download a file process by server, with HtmlUnit
Download a file process by server, with HtmlUnit ... I want to automatize file conversion available at: https://www.gpsvisualizer.com/map_input?
Read more >
Details about HtmlUnit file download - SourceForge
File downloads in real browsers. Because file download is a tricky story (at least with HtmlUnit), i like to start from the beginning...
Read more >
Download file using HtmlUnit - iTecNote
downloadhtmlunit. I am trying to download xls file for a website. When I click the link to download the file, I get a...
Read more >
Getting HTMLUnit to download files - Google Groups
This works fine in Chrome: I perform a "click" on the appropriate element and Chrome downloads the file into the Downloads directory. However,...
Read more >
com.gargoylesoftware.htmlunit.WebClient.download java ...
How to use. download. method. in. com.gargoylesoftware.htmlunit.WebClient ... Reloads the current page, possibly forcing retrieval from the server even if ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found