cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-256290%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EExtraire%20les%20fichiers%20ZIP%20du%20lien%20HTTP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-256290%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EJ'ai%20publi%C3%A9%20des%20fichiers%20ZIP%20et%20je%20souhaite%20les%20extraire%20par%20programmation%20et%20les%20stocker%20sur%20mon%20PC%20%C3%A0%20l'aide%20de%20JSL.%20Je%20ne%20sais%20pas%20%C3%A0%20l'avance%20combien%20de%20fichiers%20seront%20pr%C3%A9sents.%3C%2FP%3E%3CP%3EEst-ce%20possible%20avec%20JSL%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22zip.png%22%20style%3D%22width%3A%20760px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22zip.png%22%20style%3D%22width%3A%20760px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22zip.png%22%20style%3D%22width%3A%20760px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F22799i41FB46221876451A%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22zip.png%22%20alt%3D%22zip.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-256509%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%26nbsp%3B%3A%20Extraction%20de%20fichiers%20ZIP%20%C3%A0%20partir%20d'un%20lien%20HTTP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-256509%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EContent%20que%20tu%20puisses%20en%20tirer%20quelque%20chose%20!%20Je%20suis%20presque%20s%C3%BBr%20que%20le%20mod%C3%A8le%20pourrait%20%C3%AAtre%20am%C3%A9lior%C3%A9%2C%20en%20termes%20de%20vitesse.%20Cela%20ne%20fait%20probablement%20pas%20de%20diff%C3%A9rence%20pour%20les%20r%C3%A9pertoires%20de%20quelques%20milliers%20de%20liens%20seulement%2C%20mais%20la%20partie%20len(1)%20pourrait%20ignorer%20plus%20rapidement%20le%20texte%20qui%20n'est%20pas%20un%20lien.%20Et%20un%20mod%C3%A8le%20plus%20flexible%20pour%20les%20liens%20serait%20%C3%A9galement%20pr%C3%A9f%C3%A9rable.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F5036%22%20target%3D%22_blank%22%3E%40bryan_boone%3C%2FA%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F6331%22%20target%3D%22_blank%22%3E%20%40ErnestPasour%3C%2FA%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F12269%22%20target%3D%22_blank%22%3E%20%40paul_vezzetti%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-256506%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%26nbsp%3B%3A%20Extraction%20de%20fichiers%20ZIP%20%C3%A0%20partir%20d'un%20lien%20HTTP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-256506%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EMerci%20Craig%20pour%20la%20r%C3%A9ponse%20compl%C3%A8te.%20Je%20vais%20prendre%20des%20%C3%A9l%C3%A9ments%20des%20deux%20suggestions%20et%20les%20fusionner%20dans%20une%20fonction%20g%C3%A9n%C3%A9rique%20pour%20r%C3%A9pondre%20%C3%A0%20mes%20besoins%20actuels%20et%20futurs.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJe%20sais%20que%20je%20devrais%20utiliser%20un%20REGEXP%20pour%20trouver%20les%20liens%20de%20la%20source%20HTTP%2C%20mais%20j'esp%C3%A9rais%20une%20fonction%20'%26lt%3B%26lt%3B%20saveLink'%20pour%20la%20partie%20zip.%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECela%20fonctionnera%20parfaitement%20bien%20cependant.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EExcellente(s)%20r%C3%A9ponse(s)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-256347%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%26nbsp%3B%3A%20Extraction%20de%20fichiers%20ZIP%20%C3%A0%20partir%20d'un%20lien%20HTTP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-256347%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EOu%20peut-%C3%AAtre%20que%20c'est%20plus%20proche%20de%20ce%20que%20vous%20demandez%3A%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Epath%3D%22https%3A%2F%2Fwww.vsp.virginia.gov%2Fdownloads%2F%22%3B%20%2F%2F%20a%20page%20with%20an%20index%20of%20files.%20Yours%20may%20be%20different%20format%2C%20adjust%20pattern%20below.%0Ahtml%20%3D%20loadtextfile(path)%3B%20%2F%2F%20get%20the%20HTML%20text%20so%20we%20can%20scrape%20the%20links%0A%2F%2F%20somewhat%20custom%20pattern%20for%20scraping%20the%20links%2C%20may%20be%20specific%20to%20this%20page%0Aurls%20%3D%20%7B%7D%3B%20%2F%2F%20this%20list%20will%20collect%20the%20urls%20%0Arc%20%3D%20patmatch(html%2C%0A%20patpos(0)%2B%20%2F%2F%20make%20sure%20the%20pattern%20matches%20from%20the%20start%0A%20patrepeat(%20%2F%2F%20this%20is%20the%20loop%20that%20extracts%20the%20urls%20from%20the%20html%0A%20%20(%0A%20%20%20%2F%2F%20the%20urls%20look%20like%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2F2017%2520Virginia%2520Firearms%2520Dealers%2520Procedrures%2520Manual.pdf%22%20target%3D%22_blank%22%3E%0A%20%20%20%2F%2F%20and%20we%20want%20just%20the%20part%20between%20the%20quotation%20marks.%20Quickly%20scan%20forward%20(patBreak)%0A%20%20%20%2F%2F%20for%20a%20%26lt%3B%20then%20see%20if%20it%20matches.%20%26gt%3B%26gt%3Burl%20grabs%20the%20text%20between%20quotation%20marks.%0A%20%20%20(patbreak(%22%26lt%3B%22)%20%2B%20%22%3C%2FA%3E%3CA%20href%3D%22%5C!%26quot%3B%26quot%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%26gt%3B%20url%20%2B%20pattest(insertinto(urls%2Curl)%3B1))%0A%20%20%20%7C%20%2F%2F%20OR%0A%20%20%20patlen(1)%20%2F%2F%20skip%20forward%20one%20character%0A%20%20)%0A%20%20%2B%0A%20%20patfence()%20%2F%2F%20fence%20off%20the%20successfully%20matched%20text.%20There%20is%20no%20need%20to%20backtrack%20if%20something%20goes%20wrong.%0A%20)%20%2B%20%0A%20patrepeat(patnotany(%22%26lt%3B%22)%2C0)%20%2B%20%2F%2F%20any%20trailing%20bits%20of%20html%20are%20consumed%20here%0A%20patrpos(0)%20%2F%2F%20make%20sure%20the%20pattern%20matches%20to%20the%20end%0A)%3B%0A%0Aif(rc%3D%3D0%2C%20throw(%22pattern%20did%20not%20match%20everything%22))%3B%0Ashow(nitems(urls)%2Curls%5B6%5D)%3B%20%2F%2F%20pick%20item%206.%20You'll%20have%20a%20different%20strategy.%0A%0Afullpath%20%3D%20path%7C%7Cregex(urls%5B6%5D%2C%22%2520%22%2C%22%20%22%2CGLOBALREPLACE)%3B%2F%2F%20minimal%20effort%20to%20fix%20up%20the%20url%2C%20might%20need%20more%20work%0A%0Apdfblob%20%3D%20loadtextfile(fullpath%2Cblob)%3B%20%2F%2F%20download%20item%206%2C%20it%20is%20a%20pdf%20when%20this%20was%20written...%0Asavetextfile(%22%24temp%2Fexample.pdf%22%2Cpdfblob)%3B%20%2F%2F%20save%20it%20somewhere%3C%2FA%3E%3C%2FCODE%3E%3CA%20href%3D%22%5C!%26quot%3B%26quot%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%3C%2FA%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-256336%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%26nbsp%3B%3A%20Extraction%20de%20fichiers%20ZIP%20%C3%A0%20partir%20d'un%20lien%20HTTP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-256336%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Efichier%20zip%20de%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F4552%22%20target%3D%22_blank%22%3E%20%40wilkap%3C%2FA%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FVirtual-JMP-Users-Group%2FVJUG-July-2015-zip%2Fgpm-p%2F22641%22%20target%3D%22_blank%22%3E%20pr%C3%A9sentation%3C%2FA%3E%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Eza%3Dopen(%22https%3A%2F%2Fcommunity.jmp.com%2Fkvoqx44227%2Fattachments%2Fkvoqx44227%2Fvirtual-jug%2F12%2F1%2FVJUG%2520July%25202015.zip%22%2C%22zip%22)%3B%0Azipfiles%3Dza%26lt%3B%3C%2FCODE%3E%3CDIR%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%3C%2FCODE%3E%3C%2FDIR%3E%3C%2FPRE%3E%3CP%3Eplusieurs%20choses%20%C3%A0%20noter%3C%2FP%3E%3CUL%3E%3CLI%3Ele%20fichier%20est%20t%C3%A9l%C3%A9charg%C3%A9%20dans%20votre%20r%C3%A9pertoire%20temporaire%26nbsp%3B%3B%20l'option%20%22zip%22%20pour%20ouvrir%20renvoie%20un%20objet%20d'archive%20zip%3C%2FLI%3E%3CLI%3Evous%20pouvez%20obtenir%20une%20liste%20des%20membres%20%C3%A0%20partir%20de%20l'archive%20zip%20en%20utilisant%20%26lt%3B%3CDIR%3E%3C%2FDIR%3E%3C%2FLI%3E%3CLI%3Evous%20pouvez%20utiliser%20le%20format%20blob%20avec%20une%20archive%20zip%20pour%20lire%20des%20donn%C3%A9es%20binaires%20comme%20les%20tables%20JMP%3C%2FLI%3E%3CLI%3Ela%203%C3%A8me%20ligne%20utilise%20un%202%C3%A8me%20argument%20pour%20indiquer%20%C3%A0%20open%20que%20le%20blob%20est%20une%20table%20de%20donn%C3%A9es%20JMP%3C%2FLI%3E%3CLI%3Ela%20suppression%20de%20la%20variable%20za%20est%20n%C3%A9cessaire%20si%20vous%20r%C3%A9ex%C3%A9cutez%20tout%20le%20script%26nbsp%3B%3B%20l'objet%20d'archive%20zip%20emp%C3%AAche%20la%20r%C3%A9utilisation%20du%20fichier%20dans%20le%20r%C3%A9pertoire%20temporaire.%3C%2FLI%3E%3CLI%3Evous%20pouvez%20utiliser%20loadtextfile%2Fsavetextfile%20avec%20des%20blobs%20pour%20t%C3%A9l%C3%A9charger%20le%20fichier%20zip%20%C3%A0%20l'emplacement%20de%20votre%20choix%20(et%20le%20supprimer%20une%20fois%20termin%C3%A9)%2C%20puis%20utiliser%20l'archive%20zip%20pour%20traiter%20ce%20fichier.%3C%2FLI%3E%3CLI%3EJ'ai%20d%C3%A9j%C3%A0%20regard%C3%A9%20pour%20voir%20que%20le%204%C3%A8me%20%C3%A9l%C3%A9ment%20du%20r%C3%A9pertoire%20d'archives%20%C3%A9tait%20une%20table%20de%20donn%C3%A9es%20JMP%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
thickey1
Level III

Pull ZIP Files from HTTP Link

I have published ZIP files and want to programmatically pull them and store to my PC using JSL. I don't know up front how many files will be present.

Is this possible with JSL?

 

zip.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: Pull ZIP Files from HTTP Link

Or maybe this is closer to what you are asking:

path="https://www.vsp.virginia.gov/downloads/"; // a page with an index of files. Yours may be different format, adjust pattern below.
html = loadtextfile(path); // get the HTML text so we can scrape the links
// somewhat custom pattern for scraping the links, may be specific to this page
urls = {}; // this list will collect the urls 
rc = patmatch(html,
	patpos(0)+ // make sure the pattern matches from the start
	patrepeat( // this is the loop that extracts the urls from the html
		(
			// the urls look like <a href="2017%20Virginia%20Firearms%20Dealers%20Procedrures%20Manual.pdf">
			// and we want just the part between the quotation marks. Quickly scan forward (patBreak)
			// for a < then see if it matches. >>url grabs the text between quotation marks.
			(patbreak("<") + "<a href=\!"" + patbreak("\!"") >> url + pattest(insertinto(urls,url);1))
			| // OR
			patlen(1) // skip forward one character
		)
		+
		patfence() // fence off the successfully matched text. There is no need to backtrack if something goes wrong.
	) + 
	patrepeat(patnotany("<"),0) + // any trailing bits of html are consumed here
	patrpos(0) // make sure the pattern matches to the end
);

if(rc==0, throw("pattern did not match everything"));
show(nitems(urls),urls[6]); // pick item 6. You'll have a different strategy.

fullpath = path||regex(urls[6],"%20"," ",GLOBALREPLACE);// minimal effort to fix up the url, might need more work

pdfblob = loadtextfile(fullpath,blob); // download item 6, it is a pdf when this was written...
savetextfile("$temp/example.pdf",pdfblob); // save it somewhere
Craige

View solution in original post

4 REPLIES 4
Craige_Hales
Super User

Re: Pull ZIP Files from HTTP Link

 

zip file from @wilkap presentation 

za=open("https://community.jmp.com/kvoqx44227/attachments/kvoqx44227/virtual-jug/12/1/VJUG%20July%202015.zip","zip");
zipfiles=za<<dir;
show(zipfiles);
blob=za<<read(zipfiles[4],format(blob));
dt=open(blob,jmp);
clearglobals(za);

several things to note

  • the file is downloaded to your temp directory; the "zip" option to open returns a zip archive object
  • you can get a list of members from the zip archive using <<dir
  • you can use the blob format with zip archive for reading binary data like JMP tables
  • the 3rd line uses a 2nd argument to tell open that the blob is a JMP data table
  • clearing the za variable is needed if you rerun the whole script; the zip archive object keeps the file in the temp directory from being reused.
  • you could use loadtextfile/savetextfile with blobs to download the zip file to a location of your choice (and delete it when done) and then use the zip archive to process that file.
  • I already looked to see the 4th item in the archive directory was a JMP data table

 

Craige
Craige_Hales
Super User

Re: Pull ZIP Files from HTTP Link

Or maybe this is closer to what you are asking:

path="https://www.vsp.virginia.gov/downloads/"; // a page with an index of files. Yours may be different format, adjust pattern below.
html = loadtextfile(path); // get the HTML text so we can scrape the links
// somewhat custom pattern for scraping the links, may be specific to this page
urls = {}; // this list will collect the urls 
rc = patmatch(html,
	patpos(0)+ // make sure the pattern matches from the start
	patrepeat( // this is the loop that extracts the urls from the html
		(
			// the urls look like <a href="2017%20Virginia%20Firearms%20Dealers%20Procedrures%20Manual.pdf">
			// and we want just the part between the quotation marks. Quickly scan forward (patBreak)
			// for a < then see if it matches. >>url grabs the text between quotation marks.
			(patbreak("<") + "<a href=\!"" + patbreak("\!"") >> url + pattest(insertinto(urls,url);1))
			| // OR
			patlen(1) // skip forward one character
		)
		+
		patfence() // fence off the successfully matched text. There is no need to backtrack if something goes wrong.
	) + 
	patrepeat(patnotany("<"),0) + // any trailing bits of html are consumed here
	patrpos(0) // make sure the pattern matches to the end
);

if(rc==0, throw("pattern did not match everything"));
show(nitems(urls),urls[6]); // pick item 6. You'll have a different strategy.

fullpath = path||regex(urls[6],"%20"," ",GLOBALREPLACE);// minimal effort to fix up the url, might need more work

pdfblob = loadtextfile(fullpath,blob); // download item 6, it is a pdf when this was written...
savetextfile("$temp/example.pdf",pdfblob); // save it somewhere
Craige
thickey1
Level III

Re: Pull ZIP Files from HTTP Link

Thanks Craig for the comprehensive reply. I'll take elements of both suggestions and merge into a generic function to suit my current and future needs.

 

I know I'd have to use a REGEXP to find the links from the HTTP Source but was hoping for a '<< saveLink' function for the zip part. :) 

 

This will work perfectly fine though.

 

Great answer(s)

 

 

Craige_Hales
Super User

Re: Pull ZIP Files from HTTP Link

Glad you can get something out of it! I'm pretty sure the pattern could be improved, speed-wise. Probably doesn't make a difference for directories of only a few thousand links, but the len(1) part could skip non-link text faster. And a more flexible pattern for the links would be better too.

 

@bryan_boone @ErnestPasour @paul_vezzetti 

 

 

Craige

Recommended Articles