Question

I'm using w3m. How do I go about overriding the user agent of this text based web browser? I have tried setting -header "User-Agent: blah" as an example, but I get the following error:

w3m: Can't load blah.
Was it helpful?

Solution

I set the User-Agent by modifying the file ~/.w3m/config and modifying the user_agent line. I have the following text and it seems to work as expected: user_agent Mozilla/5.0 (Linux i686; U; w3m 0.5.3; en). That has no : or = signs in it, just so you get an idea of the syntax used.

This is with w3m version 0.5.3.

You can also set it with w3m -header 'User-Agent: blah' but the problem there is that it appears twice in the request. You can see the headers that w3m uses if you set up a netcat "webserver":

$ netcat -lp 9999
# then in another terminal:
$ w3m -header 'User-Agent: foo' http://localhost:9999
# back at netcat:
GET / HTTP/1.0
User-Agent: w3m/0.5.3
Accept: text/html, text/*;q=0.5, image/*
Accept-Encoding: gzip, compress, bzip, bzip2, deflate
Accept-Language: en;q=1.0
Host: localhost:9999
User-Agent: foo

So it sends 2 User-Agent strings, which may not be parsed correctly by the real HTTP server.

OTHER TIPS

To update and clarify a few points from @richq's good answer:

  • New w3m installs only create an empty config folder (~/.w3m)
  • Having no ':' or '=' in the user agent string (UA) is irrelevant (w3m sends whatever is on that line)
  • Confirmed that using the -header option to send a second UA is a bad idea (and unnecessary)
  • A quick, one-liner to set the UA is:

    echo 'user_agent <my-UA>' > ~/.w3m/config (Paste desired UA over <my-UA>)

  • And the much easier way to check the received UA is to simply grab one of the free UA site pages, Ex.

    w3m whatsmyuseragent.com -dump (Read UA on screen.)

w3m whatsmyua.info -o user_agent='Mozilla/5.0 (Linux i686; U; w3m 0.5.3; en)'

or

echo -e '"Mozilla/5.0 (Linux i686; U; w3m 0.5.3; en)"\n"Mozilla/5.0 (Linux x86_64; U; w3m 0.5.3; en)"' >.ua

w3m whatsmyua.info -o user_agent="$(shuf -n1 .ua)"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top