Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

akins's avatar
Level 5

Is it possible to download a file from a url using php (curl, file_get_contents, etc. etc.) that has a button that triggers a js onclick event to start download?

Using laravel/php I am trying to automatically do a daily download of a publically available file at a us gov website. The site has no direct url for the file (that I can find). Instead it has a js onclick event on a button that triggers a webform query which produces the file download request. Is there a way to get this file automatically with php (or any other method that i can put on a laravel scheduler)? Here is the link - thanks!

Link to the button: https://adviserinfo.sec.gov/IAPD/InvestmentAdviserData.aspx/#ctl00_cphMain_lnkSECReport

0 likes
4 replies
cmdobueno's avatar

You could use curl to post the form. That then can be done within a task, job, or browser action (really anywhere).

Cronix's avatar
Cronix
Best Answer
Level 67

That will be tricky. In firefox, I clicked the "State Investor Advisor Report" button and downloaded the file. Then, in Firefox, I right clicked the downloaded file and chose "copy download link", which provided

https://adviserinfo.sec.gov/IAPD/Content/BulkFeed/CompilationDownload.aspx?FeedPK=41188&FeedType=IA_FIRM_STATE

That link will download the actual file. It doesn't look like it would change, so you might try using those. Here are the other links:

SEC Investment Advisor Report: https://adviserinfo.sec.gov/IAPD/Content/BulkFeed/CompilationDownload.aspx?FeedPK=41187&FeedType=IA_FIRM_SEC

Firm XML Schema Definition: https://www.iard.com/sites/default/files/standalonefiles/firm_compilation.zip

Investment Advisor Representative Report: https://adviserinfo.sec.gov/IAPD/Content/BulkFeed/CompilationDownload.aspx?FeedPK=41189&FeedType=IA_INDVL

Rep XML Schema Definition: https://www.iard.com/sites/default/files/standalonefiles/iarcompilation_0.zip

newbie360's avatar
  1. get the page html source code

  2. strip_tags($htmlCode, '<a>') and save to array

  3. loop array preg_match write the pattern get the matches

IAPD/Content/BulkFeed/CompilationDownload.aspx?FeedPK=41187&FeedType=IA_FIRM_SEC

  1. urldecode the matches

Please or to participate in this conversation.