среда, 1 февраля 2023 г.

wget-in-Windows

Sometimes we want to use Linux command in Windows.

One of them is wget - an easy way to download sites and pages from the Internet.
There is also cURL.

Do we have them in Windows?
Natively, no, but...

The 1st way - PowerShell has command Invoke-WebRequest.

# Using PowerShell for getting a Google page:
Invoke-WebRequest http://www.google.com/ -OutFile c:\google.html
# or
Invoke-WebRequest http://www.google.com/ | -OutFile c:\google.html

# Using wget as an alias for Invoke-WebRequest (not a real wget)
wget http://www.google.com/ -OutFile c:\google.html
wget http://www.google.com/ | -OutFile c:\google.html

# Showing the results
ii c:\google.html

The 2nd way - we can install wget as a regular program - as an exe file or with Chocolatey.
Chocolatey is an extremely powerful tool with a large range of features and options.
Here is a good site about Chocolatey:
https://howchoo.com/chocolatey/install-pc-programs-using-powershell-and-chocolatey

Let's see the installation with Chocolatey.

# First install Chocolatey with PowerShell (what you see is one long line in PowerShell):
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

This will tell your system to download Chocolatey from the web and install it.
You can upgrade Chocolatey itself by running this command:
choco upgrade chocolatey



Then you can install wget with Chocolatey from PowerShell or even from a regular CMD.
choco install wget

# Use wget to pull a website to your local machine
wget --mirror --convert-links --adjust-extension --page-requisites c:\google.html





Комментариев нет:

Отправить комментарий