
1 arbeitandy Jan 19, 2013 是因v2ex不接受空白UA 修改 ${HOME}/.w3m/config 找到 user_agent 加入一常的UA串就可以了 |
2 tshwangq OP 你确认么? 我执行: w3m -header "User-Agent: Mozilla/5.0 (compatible; ooglebot/2.1; +http://www.google.com/bot.html)" http://v2ex.com 依然400 bad request |
3 arbeitandy Jan 19, 2013 -header option 只insert去,如果w3m option里有空UA串,它是覆UA配置吧。 不我不定,但你可以用w3m的 option配置UA # w3m -o user_agent="" -no-proxy -dump_head http://v2ex.com HTTP/1.1 400 Bad Request Server: nginx/1.2.1 Date: Sat, 19 Jan 2013 05:52:59 GMT Content-Type: text/html Content-Length: 172 Connection: close # w3m -o user_agent="User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" -no-proxy -dump_head http://v2ex.com Received cookie: V2EX_LANG=en HTTP/1.1 200 OK Date: Sat, 19 Jan 2013 05:53:14 GMT Content-Type: text/html; charset= Content-Length: 0 Connection: close Etag: "da39a3ee5e6b4b0d3255bfef95601890afd80709" Server: TornadoServer/2.4 Set-Cookie: V2EX_LANG=en; Path=/ |
4 arbeitandy Jan 19, 2013 一念之得是不太。乾脆搜索了一下 via: http://stackoverflow.com/questions/10257932/how-to-set-user-agent-in-w3m 的方法 * 一本地端口 $ netcat -lp 8000 * 使用 --header 配置 * 求 # w3m -header "User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" -no-proxy -dump_head http://localhost:8000 * 返回 HEAD / HTTP/1.0 User-Agent: w3m/0.5.3 Accept: text/html, text/*;q=0.5, image/*, application/* Accept-Encoding: gzip, compress, bzip, bzip2, deflate Accept-Language: en;q=1.0 Host: localhost:8000 User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) * 使用 option 配置 * 求 # w3m -o user_agent="(compatible; Googlebot/2.1; +http://www.google.com/bot.html)" -no-proxy -dump_head http://localhost:8000 * 返回 HEAD / HTTP/1.0 User-Agent: (compatible; Googlebot/2.1; +http://www.google.com/bot.html) Accept: text/html, text/*;q=0.5, image/*, application/* Accept-Encoding: gzip, compress, bzip, bzip2, deflate Accept-Language: en;q=1.0 Host: localhost:8000 * 正一下才的答: 如果用-header 加入UA,生效的上是w3m的缺省UA: 第一返回里的 User-Agent: w3m/0.5.3 非"空白UA" |
5 tshwangq OP 多谢这么认真的探索,我现在已经可以用w3m在emacs里面访问v2ex了。 不过.w3m/config文件似乎也没有作用。我只能在.emacs里面设置user-agent. |