How to get the web page source code programmatically


Fetching a web resource (including web page source) is a one-liner in Golf. First, create a new application ("get-page" here):
#new directory for this tiny app
mkdir get-page
cd get-page
#create app
gg -k get-page

Edit our sole Golf file (I use vi, but you can use anything):
vi fetch.golf

Copy and paste this - it's rather obvious what it does (it gets Google home page HTTP headers and web page source code, and it prints it out):
begin-handler /fetch public
    call-web "https://google.com" response text response-headers head
    print-out head new-line
    print-out text new-line
end-handler

Build your application (it makes a native executable):
gg -q

Run it (since we run it in command line, skip the HTTP response header, which would normally be sent to a web client):
gg -r --req="/fetch" --exec --silent-header

The result is something like this (I used ... for the remainder of the header and the web page, as they are rather long):
HTTP/2 200 
date: Sun, 17 Aug 2025 19:03:40 GMT
expires: -1
cache-control: private, max-age=0
content-type: text/html; charset=ISO-8859-1
...


<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, video
s and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content= ...

There you have it. Web programming is easy with Golf.


Copyright (c) 2019-2025 Gliim LLC. All contents on this web site is "AS IS" without warranties or guarantees of any kind.