• 请不要在回答技术问题时复制粘贴 AI 生成的内容
ikaros
V2EX  ›  程序员

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

  •  
  •   ikaros · Aug 17, 2016 · 3088 views
    This topic created in 3583 days ago, the information mentioned may be changed or developed.
    比如:

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

    返回的页面里提示:

    本站内没有找到与“ 鎭掔敓阈惰� ”相关的新闻。
    似乎是 utf-8 编码,所以是服务器不支持 utf-8 的问题么?
    4 replies    2016-08-17 15:35:27 +08:00
    zerowxxyf
        1
    zerowxxyf  
       Aug 17, 2016   ❤️ 1
    换成 gbk 编码
    anyforever
        2
    anyforever  
       Aug 17, 2016   ❤️ 1
    先 url encode 啊
    anuxs
        3
    anuxs  
       Aug 17, 2016 via iPhone   ❤️ 1
    URL 是 base64 编码。直接替换写进去当然不对。可以使用其他 http 工具库,替换中文也没事,会给你自动编码。
    ikaros
        4
    ikaros  
    OP
       Aug 17, 2016
    @zerowxxyf
    @anyforever
    @anuxs thx,用 gbk encode 之后正常了~~~
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3892 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 04:18 · PVG 12:18 · LAX 21:18 · JFK 00:18
    ♥ Do have faith in what you're doing.