<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Goquery on 月盾的博客</title>
    <link>https://blog.hopefly.top/tags/goquery/</link>
    <description>Recent content in Goquery on 月盾的博客</description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    <lastBuildDate>Mon, 27 Jul 2020 13:09:20 +0000</lastBuildDate>
    <atom:link href="https://blog.hopefly.top/tags/goquery/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>goquery 中文乱码</title>
      <link>https://blog.hopefly.top/blogdetail/5f1fb24c4536b06ac3897662/</link>
      <pubDate>Mon, 27 Jul 2020 13:09:20 +0000</pubDate>
      <guid>https://blog.hopefly.top/blogdetail/5f1fb24c4536b06ac3897662/</guid>
      <description>&lt;p&gt;乱码的情况目前有两种可能：&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;常规乱码，网页非utf-8。&lt;/li&gt;&#xA;&lt;li&gt;非常规乱码，代码导致的乱码。&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://qn-img.hopefly.top/goquery%E4%B8%AD%E6%96%87%E4%B9%B1%E7%A0%81.jpg&#34; alt=&#34;goquery中文乱码&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;关于常规乱码可参考issue&lt;a href=&#34;https://github.com/PuerkitoBio/goquery/issues/185&#34;&gt;获取中文网页有乱码的问题 #185&lt;/a&gt;&#xA;非常规乱码就像我遇到的一样，最开始以为是网页问题，使用了github.com/djimenez/iconv-go转换还是乱码，使用了golang.org/x/text/encoding/simplifiedchinese还是乱码。&#xA;试试英文网页，还是乱码。最终一点点调试发现是由header引起的。&#xA;&lt;code&gt;req.Header.Add(&amp;quot;Accept-Encoding&amp;quot;, &amp;quot;gzip, deflate&amp;quot;)&lt;/code&gt;&#xA;这一行的作用是告诉服务器浏览器要接收的数据编码是gzip,dflate，到达浏览器后会自动解码。但是我们的代码并非浏览器，不会自动解码，所以接收到的就是非常规的压缩数据。&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
