-7

I want to download a file from a website using Java. The website URL is

https://340bopais.hrsa.gov

Once you hit the URL, you will see a menu 'Reports/Files'. Click that. Now the URL will become:

https://340bopais.hrsa.gov/reports

Then click 'Daily Reports'. Then click 'Covered Entity Daily Report'. A file will be downloaded to your machine.

I want to download this file using a Java program. I inspected the button 'Covered Entity Daily Report' and found the following HTML where a Javascript script is called. How can I click on this button using a Java program?

> <a id="ContentPlaceHolder1_lnkCEDailyReport" class="btn btn-primary
> btn-lg btn-block   " title=" Click here to download the Covered Entity
> Daily Report"
> href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$lnkCEDailyReport','')">Covered Entity Daily Report</a>
Robin Green
  • 32,079
  • 16
  • 104
  • 187
Satej Koli
  • 79
  • 2
  • 15
  • can directly use [https://340bopais.hrsa.gov/reports](https://340bopais.hrsa.gov/reports) and then click 'Daily-Report' – LenglBoy Nov 24 '17 at 09:06
  • Note: with developer tools, in your browser, you should be able to see the exact URL the file is downloaded from. That may help, unless it dynamically changes. – David Conrad Nov 24 '17 at 09:22
  • Thank you @David Conrad . At least I am unable to find any URL when I press F12 while the request runs in IE. Maybe, I am missing something. If possible, can you please check from your side? – Satej Koli Nov 24 '17 at 10:13
  • Possible duplicate of [How to scrape data off a part of a site that requires user navigation](https://stackoverflow.com/questions/33328464/how-to-scrape-data-off-a-part-of-a-site-that-requires-user-navigation) – Robin Green Nov 17 '18 at 07:18

1 Answers1

1

Here is the answer for someone who has no code:

  • Use this URL: https://340bopais.hrsa.gov/reports
  • Connect to this URL with 'WebClient'
  • Get the Page with 'HtmlPage'
  • Wait until JavaScript files loaded.
  • Download execute it and download result to given path.

Mabe this already asked example code can help you.

LenglBoy
  • 1,451
  • 1
  • 10
  • 24
  • Thanks @LenglBoy . However, I am not sure after 3rd step. If possible, can you please form some initial code snippets for my example ? – Satej Koli Nov 24 '17 at 10:03
  • @SatejKoli sry don´t saw comment: have a look [here](http://java-source.net/open-source/crawlers) and use a crawler you want. They are openSource so you can get snippets there. or search for the one with best examples. I´ve got no time now, but good luck to you. – LenglBoy Dec 20 '17 at 13:11