How to Change User-Agent in Wget?
This article provides a quick overview and practical guide on how to
modify or spoof the User-Agent string when using the wget
command-line tool. By default, wget identifies itself as
“Wget/version”, which some web servers block to prevent automated
scraping. Modifying this string allows you to bypass these restrictions,
emulate different web browsers, and successfully download the required
web content.
Using the –user-agent Option
The most direct way to change the User-Agent string in
wget is by using the --user-agent option
followed by the desired string in quotes. This tells the target server
that the request is coming from a specific browser or device rather than
a command-line utility.
For example, to make wget identify itself as a standard
Google Chrome browser running on Windows, you would use the following
command:
wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" https://example.comThe Short Form Option
If you prefer shorter commands, you can use the -U
abbreviation instead of writing out the full --user-agent
flag. The functionality remains exactly the same:
wget -U "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15" https://example.comMaking the Change Permanent
If you find yourself constantly spoofing the User-Agent, you can set
a default value in your wget configuration file so you do
not have to type the flag every time.
- Open your personal
wgetconfiguration file (usually located at~/.wgetrc) in a text editor. If the file does not exist, you can create it. - Add the following line to the file:
user_agent = Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0
- Save and close the file. From this point forward, every
wgetcommand you run will automatically use this Firefox User-Agent string unless you manually override it in the terminal.