The user agent string is a line of text that web browsers and other client applications send to web servers to identify themselves. By reading the user agent string, a web server can learn about the client's type, version, and other relevant attributes. This is often utilized to serve the most compatible content for that specific browser or client.
wget, a commonly used command-line utility for downloading content from the web, has its own default user agent string. This can sometimes be problematic. For instance, certain websites block or serve different content based on the user agent. In such cases, changing the user agent of wget can be beneficial, helping you access the desired content.
Thankfully, with a simple command-line flag, you can modify the user agent string used by wget.
$ wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" https://www.example.com/
This example sets the user agent to mimic a Chrome browser on Windows 10.
echo "user_agent = Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" >> ~/.wgetrc
Be cautious about changing this permanently, especially if you're not the only user of the system.
$ wget https://www.example.com/
$ wget --user-agent="Custom User Agent String" https://www.whatsmyua.info/
Remember, changing the user agent doesn't change the actual capabilities of wget. It merely alters what wget reports to the server.
Comment anonymously. Login not required.