Keyword Index

Object: SPNet

This is a static, top-level object used to create connections to HTTP (World Wide Web) and FTP servers and to perform various related tasks. The SPNet object always exists and is never explicitly created or destroyed. Since it is a top-level object, methods in this object do not have to be preceded with "Net.".

  • getDirectoryFromURL - Returns the whole URL except for the file name and any terminating anchor.
  • getFileFromURL - Returns the file name portion of a URL. If no file name is specified, this returns an empty string. It does not attempt to substitute a name such as "index.html" as this is server dependent.
  • getFileURLFromURL - Returns the whole URL except for any terminating anchor and arguments.
  • getHostFromURL - Returns the host portion of a URL.
  • getImagesFromHTML - Extracts a list of all image references found in the given HTML text.
  • getLinksFromHTML - Extracts a list of all links found in the given HTML text.
  • getPathFromURL - Returns the path portion of a URL, i.e. the string of directory names between the host name and the file name. This can be empty.
  • getProtoFromURL - Returns the protocol portion of a URL.
  • getRefFromURL - Returns the anchor reference from a URL, i.e. the portion after a "#" hash mark, if any.
  • getTextFromHTML - Extracts the visible text from an HTML file, that is, it removes all HTML commands and other browser data and leaves only the text that would be visible to a user on the page. This is intended to allow searches for text data in the user-visible area of a Web page.
  • getURLBinary - Loads binary data from the given URL and returns it as a string value. Only HTTP URLs are supported in this version, i.e. the URL must start with "http://".
  • getURLText - Loads text from the given URL and returns it as a string value. Only HTTP URLs are supported in this version, i.e. the URL must start with "http://".
  • rawTextToHTML - Generates the HTML code necessary to display the given raw text as is.
  • SPFTP - Creates a new SPFTP object, used for send and receiving data to/from servers using the FTP protocol.
  • SPInternet - Creates a new SPInternet object, used for retrieving data from World Wide Web sites. NOTE: This version supports only the HTTP protocol, i.e. URLs starting with "http://"..
  • Method: getDirectoryFromURL

    Version added: 1.1

    Returns the whole URL except for the file name and any terminating anchor.

    String getDirectoryFromURL(urlString);

    Parameters
    Name Expected Type Description
    urlString String A complete URL

    Errors:

    No errors are reported.

    Remarks:

    Note that this only works if a complete URL ending in a file name is given. A url like "http://www.flyingobject.com/images" is ambiguous in that "images" could be a file or directory and only the server knows for sure! This method will assume the last item is a file name and remove it.

    Method: getFileFromURL

    Returns the file name portion of a URL. If no file name is specified, this returns an empty string. It does not attempt to substitute a name such as "index.html" as this is server dependent.

    String getFileFromURL(urlString);

    Parameters
    Name Expected Type Description
    urlString String A complete URL

    Errors:

    No errors are reported.

    Method: getFileURLFromURL

    Version added: 1.1

    Returns the whole URL except for any terminating anchor and arguments.

    String getFileURLFromURL(urlString);

    Parameters
    Name Expected Type Description
    urlString String A complete URL

    Errors:

    No errors are reported.

    Method: getHostFromURL

    Returns the host portion of a URL.

    String getHostFromURL(urlString);

    Parameters
    Name Expected Type Description
    urlString String A complete URL

    Errors:

    No errors are reported.

    Method: getImagesFromHTML

    Extracts a list of all image references found in the given HTML text.

    Array getImagesFromHTML(htmlString);

    Array getImagesFromHTML(htmlString, rootURL);

    Parameters
    Name Expected Type Description
    rootURL String The URL from which the HTML text was downloaded. This is needed to resolve relative path names on the page. If this is not provided, relative paths will be omitted.
    htmlString String A block of text containing HTML commands

    Returns:

    An array of strings representing the URLs of images found on the page.

    Errors:

    No errors are reported.

    Method: getLinksFromHTML

    Extracts a list of all links found in the given HTML text.

    Array getLinksFromHTML(htmlString);

    Array getLinksFromHTML(htmlString, rootURL);

    Parameters
    Name Expected Type Description
    rootURL String The URL from which the HTML text was downloaded. This is needed to resolve relative path names on the page. If this is not provided, relative links will be omitted.
    htmlString String A block of text containing HTML commands

    Returns:

    An array of strings representing the fully-qualified links found on the page.

    Errors:

    No errors are reported.

    Remarks:

    For the purposes of this method, all HREF references and all frame references are counted as links.

    Method: getPathFromURL

    Returns the path portion of a URL, i.e. the string of directory names between the host name and the file name. This can be empty.

    String getPathFromURL(urlString);

    Parameters
    Name Expected Type Description
    urlString String A complete URL

    Errors:

    No errors are reported.

    Method: getProtoFromURL

    Returns the protocol portion of a URL.

    String getProtoFromURL(urlString);

    Parameters
    Name Expected Type Description
    urlString String A complete URL

    Errors:

    No errors are reported.

    Method: getRefFromURL

    Returns the anchor reference from a URL, i.e. the portion after a "#" hash mark, if any.

    String getRefFromURL(urlString);

    Parameters
    Name Expected Type Description
    urlString String A complete URL

    Errors:

    No errors are reported.

    Method: getTextFromHTML

    Extracts the visible text from an HTML file, that is, it removes all HTML commands and other browser data and leaves only the text that would be visible to a user on the page. This is intended to allow searches for text data in the user-visible area of a Web page.

    String getTextFromHTML(htmlString);

    Parameters
    Name Expected Type Description
    htmlString String A block of text containing HTML commands

    Returns:

    String - The text extracted from the HTML.

    Errors:

    No errors are reported.

    Example:

    // This downloads an HTML page and puts up an alert box if it
    // finds the word "NetPad" in it.
    
    if (getTextFromHTML(getURLText("www.disney.com")).indexOf("NetPad") >= 0)
    {
        alert("Found a reference to NetPad!");
    }
    

    Method: getURLBinary

    Loads binary data from the given URL and returns it as a string value. Only HTTP URLs are supported in this version, i.e. the URL must start with "http://".

    SPArray getURLBinary(urlString);

    Parameters
    Name Expected Type Description
    urlString String The URL to load from, must begin with "http://"

    Returns:

    SPArray - A byte array containting the data loaded from the given URL.

    Errors:

    An exception is generated on any error.

    Remarks:

    This method provides a quick way of loading binary data (e.g. images) from a Web resource for cases where no error recovery, progress reporting or other options are needed. For more complete features, use the SPInternet object.

    Method: getURLText

    Loads text from the given URL and returns it as a string value. Only HTTP URLs are supported in this version, i.e. the URL must start with "http://".

    String getURLText(urlString);

    Parameters
    Name Expected Type Description
    urlString String The URL to load from, must begin with "http://"

    Returns:

    String - The text loaded from the given URL.

    Errors:

    An exception is generated on any error.

    Remarks:

    This method provides a quick way of loading text from a text Web resource for cases where no error recovery, progress reporting or other options are needed. For more complete features, use the SPInternet object.

    Example:

    mickeysLinks = getLinksFromHTML(getURLText("www.disney.com"));
    writeFile("c:/disney links.txt", "" + mickeysLinks;
    

    Method: rawTextToHTML

    Version added: 1.1

    Generates the HTML code necessary to display the given raw text as is.

    String rawTextToHTML(rawString);

    Parameters
    Name Expected Type Description
    rawString String A block of text to convert to HTML

    Returns:

    String - The text converted to HTML.

    Errors:

    No errors are reported.

    Remarks:

    If the input string contains no characters that are special in HTML, no changes are made and the same string is returned. If the input string contains any characters that could be intepreted as special by an HTML interpreter, they will be to the appropriate &xxx; HTML metachar.

    Example:

    // This displays a sample of HTML code on an HTML page, i.e. escaping the
    // HTML tags so they won't be intepreted by the browser.
    
    text = rawTextToHTML("<TITLE>The Page Title</TITLE>");
    file = "c:/Script Pilot Samples/html example.html";
    writeFile(file, "<html>" + text + "</html>");
    run(file);
    

    Method: SPFTP

    Creates a new SPFTP object, used for send and receiving data to/from servers using the FTP protocol.

    SPFTP SPFTP(serverName, userName, password);

    Creates an unnamed SPFTP object connected to the given server.

    SPFTP SPFTP(objectName, serverName, userName, password);

    Create a named SPFTP object. The given name can be used to connect to events generated by object in the process of interacting with servers.

    Parameters
    Name Expected Type Description
    userName String The user name required to connect to the server. If the server supports anonymous connections, this can be "anonymous".
    password String The password required to connect to the server. If the server supports anonymous connections, this can be your email address.
    objectName String A name for this connection object. This is used to respond to events generated during the progress of FTP transactions. The name of an event handler will be objectName_eventName.
    serverName String The server name, e.g. "ftp.company.com"

    See Also:

  • SPFTP
  • Method: SPInternet

    Creates a new SPInternet object, used for retrieving data from World Wide Web sites. NOTE: This version supports only the HTTP protocol, i.e. URLs starting with "http://"..

    SPInternet SPInternet();

    Creates an unnamed SPInternet object.

    SPInternet SPInternet(name);

    Create a named SPInternet object. The given name can be used to connect to events generated by object in the process of interacting with servers.

    Parameters
    Name Expected Type Description
    name String The name of the object that will be used to identify event handlers for this object.

    Example:

    h = SPInternet("Web");
    h.getURL("http://www.disney.com");
    
    function Web_Done()
    {
        writeln("We got it!");
    }
    

    See Also:

  • SPInternet