V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
tshwangq
V2EX  ›  Linux

w3m 访问不了v2ex :(

  •  
  •   tshwangq ·
    tshwangq · 2013-01-19 12:47:01 +08:00 · 3702 次点击
    这是一个创建于 4108 天前的主题,其中的信息可能已经有所发展或是发生改变。
    最近喜欢窝在emacs里面干所有事情。
    不过访问v2ex的时候出错了。
    显示 400 bad request ngninx/1.2.1
    7 条回复    1970-01-01 08:00:00 +08:00
    arbeitandy
        1
    arbeitandy  
       2013-01-19 13:10:31 +08:00
    這個問題是因為v2ex不接受空白UA
    修改 ${HOME}/.w3m/config
    找到
    user_agent
    加入一個常規的UA串就可以了
    tshwangq
        2
    tshwangq  
    OP
       2013-01-19 13:28:24 +08:00
    你确认么?
    我执行:

    w3m -header "User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" http://v2ex.com

    依然400 bad request
    arbeitandy
        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=/
    arbeitandy
        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"
    tshwangq
        5
    tshwangq  
    OP
       2013-01-19 20:25:05 +08:00
    多谢这么认真的探索,我现在已经可以用w3m在emacs里面访问v2ex了。
    不过.w3m/config文件似乎也没有作用。我只能在.emacs里面设置user-agent.
    Livid
        6
    Livid  
    MOD
       2013-01-19 21:17:00 +08:00 via iPhone
    @tshwangq 看到的是移动版的页面么?
    tshwangq
        7
    tshwangq  
    OP
       2013-01-19 22:05:23 +08:00
    @Livid 普通的页面
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   972 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 19:39 · PVG 03:39 · LAX 12:39 · JFK 15:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.