V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ikaros
V2EX  ›  程序员

抓取网页时,在 url 里 replace 搜索中文关键词之后服务器返回的关键词编码不正确

  •  
  •   ikaros · 2016-08-17 12:06:11 +08:00 · 2397 次点击
    这是一个创建于 2802 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如:

    http://news.sogou.com/news?&query=site:finance.qq.com+恒生银行&sort=1&mode=2

    返回的页面里提示:

    本站内没有找到与“ 鎭掔敓阈惰� ”相关的新闻。
    似乎是 utf-8 编码,所以是服务器不支持 utf-8 的问题么?
    4 条回复    2016-08-17 15:35:27 +08:00
    zerowxxyf
        1
    zerowxxyf  
       2016-08-17 12:13:39 +08:00   ❤️ 1
    换成 gbk 编码
    anyforever
        2
    anyforever  
       2016-08-17 13:59:20 +08:00   ❤️ 1
    先 url encode 啊
    anuxs
        3
    anuxs  
       2016-08-17 14:03:28 +08:00 via iPhone   ❤️ 1
    URL 是 base64 编码。直接替换写进去当然不对。可以使用其他 http 工具库,替换中文也没事,会给你自动编码。
    ikaros
        4
    ikaros  
    OP
       2016-08-17 15:35:27 +08:00
    @zerowxxyf
    @anyforever
    @anuxs thx,用 gbk encode 之后正常了~~~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1134 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 23:42 · PVG 07:42 · LAX 16:42 · JFK 19:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.