View Raw SPL
/*****************************************************************************
* *
* WEBREADHTML.SPL Copyright (C) 2020 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Returns the HTML source from a URL *
* *
* Revisions: 20 Aug 2020 RRR Creation *
* *
*****************************************************************************/
#if @HELP_WEBREADHTML
WEBREADHTML
Purpose: Returns the HTML source text for a URL.
Syntax: WEBREADHTML("url", "header")
"url" - A string, the URL string.
"header" - A string, the HTML header string. Defaults to empty,
no header.
Returns: A string, the HTML source text for the URL.
Example:
webreadhtml("www.dadisp.com")
Displays the source HTML text for the DADiSP home page.
Example:
dsphtml = webreadhtml("www.dadisp.com")
Same as above except the source HTML text is assigned to the
variable DSPHTML.
Remarks:
WEBREADHTML returns the HTML source text for the input URL.
If no output is provided, the text is displayed in a pop-up
dialog box.
See VIEWHTML to display the web page for a source URL.
See VIEWTEXT to display the HTML source text.
See Also:
Geturl
Viewhtml
Viewtext
Webreadjson
Webreadimage
#endif
/* return HTML source for a URL */
webreadhtml(url = {}, header = "")
{
local htmlfile, html, status, err, p, fname, ext;
if (not(isstring(url)))
{
error(sprintf("%s - input URL required", __FUNC__));
}
header = webformatheader(header);
(html, status, err) = geturl(url, "", header, "binary");
if (status == 1)
{
if (outargc > 0)
{
/* return HTML as string */
return(strchars(html));
}
else
{
/* show HTML code */
viewtext(strchars(html), url);
}
}
else
{
error(sprintf("%s - %s", __FUNC__, err));
}
}