Stephen's Space


WebLib

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

WebLib Basics

Top-Level Handlers

Handler Description
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 specified 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.

Script Objects

WiFiManager

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

Instance Handlers
Handler Description
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
Handler Description
ping over numAttempts Pings the site's host the specified 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
Property Type Description
title text The title of the website.
description text A brief description of the website's content.
URL text The URL of the website.
HTML text The raw HTML of the website.
visibleText text The visible text of the website.
favicon NSImage The favicon of the website.
host text The host (i.e. base domain) of the website.
scheme text The URL scheme of the URL.
pathString text The path component of the URL.
query text The query component of the URL.
queryItems record of text The query component of the URL.
port number The port component of the URL.

WLWebScraper

Class for scraping the contents of a website.

Instance Handlers
Handler Description
itemsWithTypes:theTypes forKeyPath:theKeyPath Extracts items of the specified type from the website.
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
Property Type Description
target text The target URL of the website.

Constants

Name Value Description
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.