[求助] clj-http抓取gbk的HTML到本地后是乱码

69 views
Skip to first unread message

胡正全

unread,
May 12, 2014, 5:37:19 AM5/12/14
to cn-cl...@googlegroups.com
求助大家

用clj-http写了一个爬虫类程序,抓取UTF8的网页没问题,抓取GBK的网页是乱码。

程序:

(ns test.core
  (:require [clj-http.client :as client]
            [http.async.client :as http]))


我是用$lein run test.core > out 输出的文件,输出文件见附件,指定UTF8和GBK打开文件看到的都是乱码,另外用http.async.client也试了,结果相同。

谁能指点一下这是怎么回事,谢谢
out.txt

dennis zhuang

unread,
May 12, 2014, 5:50:01 AM5/12/14
to cn-cl...@googlegroups.com
(println (client/get "http://bj.people.com.cn/n/2014/0512/c82847-21183630.html" {:as "GBK"}))

就正常了

clj-http提供的auto detection还是比较初级的。还是需要自己的detect字符编码,content-type头,页面meta等信息,然后做相应的转码。



--
中文社区博客:http://blog.clojure.cn/
中文问答网站:http://ask.clojure.cn/
中文邮件列表:https://groups.google.com/d/forum/cn-clojure?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛中的“CN-Clojure”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到cn-clojure+...@googlegroups.com
要发帖到此论坛,请发送电子邮件至cn-cl...@googlegroups.com
通过http://groups.google.com/group/cn-clojure访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout



--
庄晓丹
Email:        killm...@gmail.com xzh...@avos.com
Site:           http://fnil.net
Twitter:      @killme2008


胡正全

unread,
May 12, 2014, 6:22:03 AM5/12/14
to cn-cl...@googlegroups.com
谢谢dennis,试了一下果然可行 :)

在 2014年5月12日星期一UTC+8下午5时50分01秒,dennis写道:
(println (client/get "http://bj.people.com.cn/n/2014/0512/c82847-21183630.html" {:as "GBK"}))

就正常了

clj-http提供的auto detection还是比较初级的。还是需要自己的detect字符编码,content-type头,页面meta等信息,然后做相应的转码。

在 2014年5月12日 下午5:37,胡正全 <fro...@gmail.com>写道:
求助大家

用clj-http写了一个爬虫类程序,抓取UTF8的网页没问题,抓取GBK的网页是乱码。

程序:

(ns test.core
  (:require [clj-http.client :as client]
            [http.async.client :as http]))


我是用$lein run test.core > out 输出的文件,输出文件见附件,指定UTF8和GBK打开文件看到的都是乱码,另外用http.async.client也试了,结果相同。

谁能指点一下这是怎么回事,谢谢

--
中文社区博客:http://blog.clojure.cn/
中文问答网站:http://ask.clojure.cn/
中文邮件列表:https://groups.google.com/d/forum/cn-clojure?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛中的“CN-Clojure”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到cn-clojure+unsubscribe@googlegroups.com

要发帖到此论坛,请发送电子邮件至cn-cl...@googlegroups.com
通过http://groups.google.com/group/cn-clojure访问此论坛。
要查看更多选项,请访问https://groups.google.com/d/optout
Reply all
Reply to author
Forward
0 new messages