Read web content to a file
By jasperdg on Mar 25, 2010 | In Computers, Programmeren
A function to read a webpage's content into a (cached) file.
UrlToFile.prg
LPARAMETERS tcRemote
* URL reader from Fox Wiki site: http://fox.wikis.com/wc.dll?Wiki~ReadUrl~VFP
* Accept URL
* Return cached filename
* Note: file gets deleted after first contact. So do filetostr() first! After file() it will be gone.
LOCAL lnResult, lcTargetFile
lcTargetFile = REPLICATE(CHR(0), 250)
DECLARE INTEGER URLDownloadToCacheFile IN urlmon;
INTEGER lpUnkcaller, STRING szURL, STRING @szFileName,;
INTEGER dwBufLength, INTEGER dwReserved, INTEGER pBSC
WAIT WINDOW NOWAIT "Downloading remote file..."
lnResult = URLDownloadToCacheFile(0, tcRemote, @lcTargetFile,LEN(lcTargetFile), 0,0)
WAIT CLEAR
RETURN STRTRAN(lcTargetFile, Chr(0), "")
And wrapper UrlToStr.prg:
LPARAMETERS tcRemote
* Wrapper for UrlToFile to read web content into a string
LOCAL lcFile,lcResult
lcFile = UrlToFile(tcRemote)
lcResult = FILETOSTR( lcFile)
RETURN lcResult
| « Pluizerd voor ondermeer inspirerende workshops en leuke, duurzame accessoires | Webpagina's afdrukken zonder de rommel » |
