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

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

  •  
  •   ikaros · Aug 17, 2016 · 3340 views
    This topic created in 3735 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
    zerowxxyf
    Aug 17, 2016❤️1
    1
    换成 gbk 编码
    anyforever
    anyforever
    Aug 17, 2016❤️1
    2
    先 url encode 啊
    anuxs
    anuxs
    Aug 17, 2016 via iPhone❤️1
    3
    URL 是 base64 编码。直接替换写进去当然不对。可以使用其他 http 工具库,替换中文也没事,会给你自动编码。
    ikaros
    ikaros
    OP
    Aug 17, 2016
    4
    @zerowxxyf
    @anyforever
    @anuxs thx,用 gbk encode 之后正常了~~~
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   643 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 18:37 · PVG 02:37 · LAX 10:37 · JFK 13:37
    ♥ Do have faith in what you're doing.