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.
See also
Articles
article-capi  
article-cookies  
article-debug  
article-distributed  
article-encryption  
article-fetch-web-page  
article-fifo  
article-file-manager  
article-hello-server  
article-hello-world  
article-hello-world-service  
article-hello-world-service-web  
article-how-to-create-golf-application  
article-json  
article-language  
article-mariadb  
article-memory-safety  
article-memory-safety-web  
article-notes-postgres  
article-random  
article-regex  
article-remote-call  
article-request-function  
article-security  
article-sendmail  
article-server  
article-shopping  
article-sqlite  
article-statements  
article-status-check  
article-tree  
article-tree-web  
article-vim-coloring  
article-web-framework-for-c-programming-language  
article-what-is-golf  
article-what-is-web-service  
See all
documentation


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