Methods of Retrieving the Source Code of a Web Page

Hey Folks,

A very common automation task is retrieving the source of a web page and mining it for information.

To do that we have to first acquire the source of the page, and there are several ways of doing this using Keyboard Maestro.

Keyboard Maestro 8 to the Rescue

Keyboard Maestro 8 added a Get URL action that makes the job super simple:

Retrieve the Source of a Web Page with a Keyboard Maestro Get URL Action.kmmacros (4.2 KB)

The Shell Game

Up until Keyboard Maestro added its own Get URL action the most common method of scraping code off the web was to use the Unix executable Curl.

Retrieve the Source of a Web Page with Curl.kmmacros (4.5 KB)

Curl comes stock with the macOS.

There are other Unix executables available for siphoning the web like Wget, but you have to have the interest and skill to install them yourself. (Or you can use a package manager like MacPorts or Homebrew.)

Adventures in AppleScript

Since the advent of macOS 10.10 (Yosemite) we can also do the job quite neatly with AppleScript:

Retrieve the Source of a Web Page with AppleScript.kmmacros (5.8 KB)