Recent

Author Topic: [SOLVED] Help for downloand file  (Read 1696 times)

magleft

  • Jr. Member
  • **
  • Posts: 94
[SOLVED] Help for downloand file
« on: May 04, 2023, 08:17:56 am »
Hello. I want to downloand file from following url
https://1click.minagric.gr/oneClickUI/frmFytoPro.zul?lang=en

I want to downloand file with Lazarus  with synapse but can' t find url of file.
 
Can someone help me?

Thanks in advance.
« Last Edit: June 02, 2023, 08:31:06 pm by magleft »
windows 10 64

bobby100

  • Full Member
  • ***
  • Posts: 149
    • Malzilla
Re: Help for downloand file
« Reply #1 on: May 04, 2023, 08:29:57 am »
The download link is in an invisible iframe, and the iframe opens by the JavaScript after you click on "here".
Code: Pascal  [Select][+][-]
  1. <iframe src="/oneClickUI/zkau/view/z_det/dwnmed-0/ifc1/dbSYSPEST.zip" id="zk_download" name="zk_download" style="visibility:hidden;width:0;height:0;border:0" frameborder="0"></iframe>
I do not know if the link is persistent, or it is generated every time you click on "here".
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

TRon

  • Hero Member
  • *****
  • Posts: 1512
Re: Help for downloand file
« Reply #2 on: May 04, 2023, 08:39:26 am »
Seems like the link is not persistent  %)

magleft

  • Jr. Member
  • **
  • Posts: 94
Re: Help for downloand file
« Reply #3 on: May 04, 2023, 08:41:08 am »
Thanks for reply.
Every time who pres <here> button start downloand a file. If pres right button on downloand file i copy
a link of file but is different every time. For example following links.

https://1click.minagric.gr/oneClickUI/zkau/view/z_i2e/dwnmed-0/g3k1/dbSYSPEST.zip
https://1click.minagric.gr/oneClickUI/zkau/view/z_i2e/dwnmed-1/tnp/dbSYSPEST.zip

I think that means generete link every time when press "here" button.
So how could the download of the file be done automatically through lazarus?
windows 10 64

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: Help for downloand file
« Reply #4 on: May 04, 2023, 01:03:34 pm »

I can get a file via windows bitsadmin, but nothing to do with Lazarus, only freepascal.
Code: Pascal  [Select][+][-]
  1.  
  2.  
  3.  
  4. uses
  5. sysutils;
  6.  
  7.  function  shell(s:pchar):integer ; cdecl external 'msvcrt.dll' name 'system';
  8.  
  9. function filelength(filename:ansistring):longword;
  10. Var F : File of byte;
  11. var L:longword;
  12. begin
  13. Assign (F,filename);
  14.   Reset (F);
  15.   L:=FileSize(F);
  16.   Close (F);
  17.   exit(L);
  18. end;
  19.  
  20. procedure loadfile(var content: ansistring;filename:ansistring);
  21.    Var Fin : File;
  22.    Var x:int32;
  23.    begin
  24.    x:=filelength(filename);
  25.    setlength(content,x);
  26.    Assign (Fin,filename);
  27.    Reset (Fin,x);
  28.    BlockRead (Fin,content[1],1);
  29.    close(fin);
  30. end;
  31.  
  32.  
  33. procedure download(site:ansiString;newfile:ansistring);
  34. var
  35. f,content:ansistring;
  36. begin
  37. content:='';
  38. if fileexists(newfile) then deletefile(newfile);
  39.   If (pos(' ',site) <>0) Then site:=Chr(34)+site+Chr(34);
  40.   f:='type nul > ' +GetCurrentDir +'\'+newfile; // create empty file
  41.   shell (pchar(f));
  42.   shell('bitsadmin /reset');
  43.   shell ('bitsadmin /create mydownload');
  44.   f:='bitsadmin  /transfer mydownload  /download  /priority normal /DYNAMIC ' +  site +' '+ Chr(34) + GetCurrentDir +'\'+ newfile +Chr(34);
  45.   Shell(pchar(f));
  46.   shell ('bitsadmin /complete mydownload');
  47.   if (filelength(newfile)<>0) then loadfile(content,newfile) else exit;
  48.   f:=Chr(34) +GetCurrentDir +  '\'+newfile + Chr(34);
  49.   If (Length(content)>4) Then
  50.     Shell (pchar(f));
  51. End;
  52.  
  53.  
  54. var
  55. site:ansistring='https://1click.minagric.gr/oneClickUI/frmFytoPro.zul?lang=en';
  56.  
  57. begin
  58. shell('Title Please wait a few seconds until Job completed');
  59. download(site,'New.file');
  60. writeln('Press return to finish . . .');
  61. readln;
  62. end.
  63.  
  64.  
  65.  

magleft

  • Jr. Member
  • **
  • Posts: 94
Re: Help for downloand file
« Reply #5 on: May 05, 2023, 06:30:39 am »
BobDog thanks for Reply. But i can't downloand file 'Syspest.zip' when downloand freepascal and compile your code.
I change your code in line 59 as download(site,'SYSPEST.ZIP');
besides, I would be interested in the process being done through the Lazarus application.
Anyway, I would like to thank you for your help and time
windows 10 64

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: Help for downloand file
« Reply #6 on: May 05, 2023, 12:18:32 pm »

Sorry it doesn't work magleft.
The site containing SYSPEST.ZIP always says:
"The requested resource is no longer available, and no forwarding address is known."
So that is the reason I reckon.
I also tested through pascal code using powershell -- with the same result.

To run the code in Lazarus I would use file, new, simple program,  get rid of the form and code windows if they appear. Paste the code to the source editor , get rid of the top few lines :


program Project1;

begin
end.


Then quick compile and then run without de-bugging.
(But I don't use Lazarus, maybe only to test out code sometimes).


         





rvk

  • Hero Member
  • *****
  • Posts: 5481
Re: Help for downloand file
« Reply #7 on: May 05, 2023, 12:40:21 pm »
I change your code in line 59 as download(site,'SYSPEST.ZIP');
As already stated... direct download isn't possible.
You would need to execute the javascript on that site to get a correct unique temporary downloadlink.

The only option I see is simulating the click on "Here" in a browser (or browsercomponent) which can interpret javascript.

loaded

  • Hero Member
  • *****
  • Posts: 785
Re: Help for downloand file
« Reply #8 on: May 05, 2023, 12:40:50 pm »
Download link ;
Code: XML  [Select][+][-]
  1. https://1click.minagric.gr/oneClickUI/zkau/view/z_m4a/dwnmed-0/d8t1/dbSYSPEST.zip
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

rvk

  • Hero Member
  • *****
  • Posts: 5481
Re: Help for downloand file
« Reply #9 on: May 05, 2023, 12:42:37 pm »
Download link ;
Code: XML  [Select][+][-]
  1. https://1click.minagric.gr/oneClickUI/zkau/view/z_m4a/dwnmed-0/d8t1/dbSYSPEST.zip
From the "z_m4a/dwnmed-0" in the link you can see that this is a temporary link.
It will expire within a short period of time.
(read the previous answers)

TRon

  • Hero Member
  • *****
  • Posts: 1512
Re: Help for downloand file
« Reply #10 on: May 05, 2023, 12:45:05 pm »
@loaded:
as rvk stated.

The javascript generates a temporary link. Just clear the cache of your browser and download the file again to see for yourself that the link is different this time. A simple use of wget using that same URL that you posted will fail as well.

fwiw: the "z_m4a/dwnmed-0" part can be obtained from the html but the "d8t1" part is generated by javascript after pressing the button.
« Last Edit: May 05, 2023, 12:48:23 pm by TRon »

loaded

  • Hero Member
  • *****
  • Posts: 785
Re: Help for downloand file
« Reply #11 on: May 05, 2023, 01:26:45 pm »
From the "z_m4a/dwnmed-0" in the link you can see that this is a temporary link.

The javascript generates a temporary link. Just clear the cache of your browser and download the file again to see for yourself that the link is different this time. A simple use of wget using that same URL that you posted will fail as well.

Yes you are right, I didn't know that. ;D
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

magleft

  • Jr. Member
  • **
  • Posts: 94
Re: Help for downloand file
« Reply #12 on: May 31, 2023, 07:28:09 am »
After querying the page administrator, the following response was given:

Checked the link and added a constant btnid="bdf" attribute that you can use.

How can it be used so that the file can be downloaded through the synapse
windows 10 64

rvk

  • Hero Member
  • *****
  • Posts: 5481
Re: Help for downloand file
« Reply #13 on: May 31, 2023, 09:29:43 am »
After querying the page administrator, the following response was given:

Checked the link and added a constant btnid="bdf" attribute that you can use.

How can it be used so that the file can be downloaded through the synapse
You can't. You should ask how you could use that attribute to retrieve the file.

There is an attribute btnid added but you don't have javascript to execute it.
So you still don't know what the underlying filename would be.

(The administrator probably thought you wanted to automate the DOM-object and simulate a click on that element. But you can't simulate anything without a javascript interpreter.)

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1218
Re: Help for downloand file
« Reply #14 on: June 01, 2023, 08:33:10 am »
Hello,
here is a code to download the file and display the url of this file using WebDriver4L v0.2 (windows + automating chrome)
Code: Pascal  [Select][+][-]
  1. uses  Webdriver4L;
  2. procedure TForm1.BtMinagridClick(Sender: TObject);
  3. var Robot : TWebDriver;
  4.     hereLnk,dlsrc : TWebElement;
  5. Begin
  6. Try
  7.    Robot := TChromeDriver.Create(nil);
  8.    Robot.StartDriver(ExtractFileDir(Paramstr(0)) + '\chromedriver.exe',
  9.     '--user-data-dir d:\temp\Web4L');
  10.   Sleep(2000);
  11.   Robot.NewSession;
  12.   Robot.Implicitly_Wait(2000);
  13.   Robot.Set_Window_Size(1280, 1024);
  14.   Robot.GetURL('https://1click.minagric.gr/oneClickUI/frmFytoPro.zul?lang=en');
  15.   hereLnk := Robot.FindElementByXPath('//span[@*[local-name() = "ns:btnid"][. ="bdf"]]');
  16.   hereLnk.click();
  17.   dlsrc := Robot.FindElementByID('zk_download');
  18.   Memo1.Append(dlsrc.AttributeValue('src'));
  19.   Sleep(30000);
  20.   Robot.Quit;
  21.   finally
  22.   Robot.Free;
  23.   end;
  24. end;
  25.  
Friendly J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

 

TinyPortal © 2005-2018