1
arbeitandy 2013-01-19 13:10:31 +08:00
這個問題是因為v2ex不接受空白UA
修改 ${HOME}/.w3m/config 找到 user_agent 加入一個常規的UA串就可以了 |
2
tshwangq OP 你确认么?
我执行: w3m -header "User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" http://v2ex.com 依然400 bad request |
3
arbeitandy 2013-01-19 13:59:09 +08:00
-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=UTF-8 Content-Length: 0 Connection: close Etag: "da39a3ee5e6b4b0d3255bfef95601890afd80709" Server: TornadoServer/2.4 Set-Cookie: V2EX_LANG=en; Path=/ |
4
arbeitandy 2013-01-19 14:49:56 +08:00
一念之間覺得還是不太對。乾脆搜索了一下
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. |