How To View A Page Source Code Via Curl In Terminal (Shell)
How To View A Page Source Code Via Curl In Terminal (Shell)
As much as you can navigate to a webpage, look for a file on the web page and download such file, you can also download internet files, web pages and source codes through the Command Line Interface (CLI).
A stock CLI usually comes preloaded with almost every OS.
The stock CLI on Windows, is the Windows command (cmd.exe).
While for MacOS and Linux, you can access the shell through the terminal, this is not so on Windows.
For Windows, you need access to the shell through a terminal called git bash.
There are other such CLI's available for Windows windows. Another popular one is the cygwin terminal.
To download a file via shell in Windows, Mac, Linux, Unix or any other operating system, you'll need to use the curl command.
The 'curl' command which means 'see uniform resource locator', can be used to download internet files, web pages or view web source codes.
To view a page source code, enter the following command in your terminal:
curl -L webaddress.
Replace 'webaddress' with the actual address of the webpage you wish to view.
the '-L' in the script means 'follow redirect'. Excluding it gives you a basic source code which is not much useful. Including it gives you a more comprehensive compressed JavaScript source code as you would see in your browser dev tools.
Post a Comment