You can find the script here.

#! /bin/sh
# remove browsing data from w3m

# If w3m is running, exit
if test -n "$( pgrep w3m )"; then 
    echo w3m is running, exiting...
    exit 0
fi

# If has cookies, delete
if [ -e ~/.w3m/cookie ]; then 
    echo removing cookie file...
    rm ~/.w3m/cookie
fi

# If has history file, keep only last 20 entries
if [ -e ~/.w3m/history ]; then 
    if [ "$(cat .w3m/history | wc -l)" -gt "20" ]; then 
	tail -n 20 ~/.w3m/history > /tmp/history && mv /tmp/history ~/.w3m/history
	echo history truncated
    fi
fi

# If has cache files, delete
if test -n "$(find ~/.w3m -name \*w3mcache\* )"; then
    echo removing cache...
    rm ~/.w3m/w3mcache*
fi

# If has source files, delete
if test -n "$(find ~/.w3m -name \*w3msrc\* )"; then
    echo removing src files...
    rm ~/.w3m/w3msrc*
fi

# If has tmp files, delete
if test -n "$(find ~/.w3m -name \*w3mtmp\* )"; then
    echo removing tmp files...
    rm ~/.w3m/w3mtmp*
fi