Stephen's Space

WebLib

Get properties of websites, extract their visible text, save them to PDFs or images, and more.

WebLib Basics

Script Objects

WiFiManager

Wrapper object around CoreWLAN functionality providing easy access to complex operations.

Instance Handlers

disconnect() - Disconnects from the current WiFi network.

disable() - Disables the WiFi interface.

enable() - Enables the WiFi interface.

getMACAddress() - Gets the MAC address of the WiFi interface. Returns a text string.

getRSSI() - Gets the current aggregate RSSI measurement for the WiFi interface.

getSSID() - Gets the SSID of the current WiFi network.

connectToNetwork:networkName usingPassword:thePassword - Attempts to connect to the network with the given name, using the provided password. Both parameters must be text strings. Returns true if the connection was successful, false otherwise.

getAvailableNetworks() - Scans for available WiFi networks and returns the list of network SSIDs.


WLWebsite

Wrapper object around website URLs and data providing access to complex operations.

Instance Handlers

ping over numAttempts - Pings the site's host the speciifed number of times, returning the average. numAttempts must be an integer number, and it defaults to 1. Returns the average ping time in milliseconds as a number.

save in filePath as fileType - Saves the website as a text file, HTML file, PDF, PNG, or JPG. filePath must be a valid path as a text string, and fileType must be one of PNG, JPG, HTML, PDF, or TXT. Returns true if the website was saved successfully, false otherwise.

open - Opens the website in the default browser.

Instance Properties

title - The title of the website.

description - A brief description of the website's content.

URL - The URL of the website as a text string.

HTML - The raw HTML of the website as a text string.

visibleText - The visible text of the website as a text string.

favicon - The favicon of the website as an NSImage object.

host - The host (i.e. base domain) of the website as a text string.

scheme - The URL scheme of the URL as a text string.

pathString - The path component of the URL as a text string.

query - The query component of the URL as a text string.

queryItems - The query component of the URL as a record of text strings.

port - The port component of the URL as a number.


WLWebScraper

Class for scraping the contents of a website.

Instance Handlers

itemsWithTypes:theTypes forKeyPath:theKeyPath - Extracts items of the specified type from

extractLinks() - Extracts all links from the website. Returns a list of text strings.

extractPhoneNumbers() - Extracts all phone numbers from the website. Returns a list of text strings.

extractTransitInfo() - Extracts all transit information from the website. Returns a list of text strings.

extractDates() - Extracts all dates from the website. Returns a list of text strings.

extractAddresses() - Extracts all addresses from the website. Returns a list of text strings.

Instance Properties

target - The target URL of the website as a text string.


Top-Level Handlers

websiteWithURLString:URLString - Creates a new WLWebsite object for a given URL. URLString must be a text string. Returns the newly created WLWebsite object.

WebSite for URLString - Creates a new WLWebsite object for a given URL. URLString must be a text string. Returns the newly created WLWebsite object.

ping for site over numAttempts - Pings the site's host the speciifed number of times, returning the average ping time in milliseconds. site must be a WLWebsite object or a text string, and numAttempts must be an integer number. Returns the average ping time in milliseconds as a number.

webScraperForURLWithString:URLString - Creates a new web scraper for a given URL. URLString must be a text string. Returns the newly created WLWebScraper object.

WebScraper for theWebsite - Creates a new web scraper for a given website. theWebsite must be an WLWebsite object. Returns the newly created WLWebScraper object.

percentEncoding for theString - Encodes the provided string for use in a URL. Returns the encoded string as a text string.

percentDecoding for theString - Decodes the provided string from a URL. Returns the decoded string as a text string.


Constants

PNG = "PNG" - The PNG file type.

JPG = "JPG" - The JPG file type.

HTML = "HTML" - The HTML file type.

PDF = "PDF" - The PDF file type.

TXT = "TXT" - The TXT file type.