让 htmlParse 与希伯来语一起工作?
我希望 htmlParse 能够很好地处理希伯来语,但它不断地扰乱我输入的页面中的希伯来语文本。
例如:
# why can't I parse the Hebrew correctly?
library(RCurl)
library(XML)
u = "http://humus101.com/?p=2737"
a = getURL(u)
a # Here - the hebrew is fine.
a2 <- htmlParse(a)
a2 # Here it is a mess...
这些似乎都不能修复它:
htmlParse(a, encoding = "utf-8")
htmlParse(a, encoding = "iso8859-8")
这是我的语言环境:
> Sys.getlocale()
[1] "LC_COLLATE=Hebrew_Israel.1255;LC_CTYPE=Hebrew_Israel.1255;LC_MONETARY=Hebrew_Israel.1255;LC_NUMERIC=C;LC_TIME=Hebrew_Israel.1255"
>
有什么建议吗?
I wish to be able to have htmlParse work well with Hebrew, but it keeps to scramble the Hebrew text in pages I feed into it.
For example:
# why can't I parse the Hebrew correctly?
library(RCurl)
library(XML)
u = "http://humus101.com/?p=2737"
a = getURL(u)
a # Here - the hebrew is fine.
a2 <- htmlParse(a)
a2 # Here it is a mess...
None of these seem to fix it:
htmlParse(a, encoding = "utf-8")
htmlParse(a, encoding = "iso8859-8")
This is my locale:
> Sys.getlocale()
[1] "LC_COLLATE=Hebrew_Israel.1255;LC_CTYPE=Hebrew_Israel.1255;LC_MONETARY=Hebrew_Israel.1255;LC_NUMERIC=C;LC_TIME=Hebrew_Israel.1255"
>
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在对
getURL
和htmlParse
的调用中指定UTF-8
结尾。这些区域设置问题总是很难弄清楚。当我输入
cat(a)
时(在getURL
中指定UTF-8
编码后),我看到he.wrodpress.org
页面声称是 UTF-8:,但是希伯来语位是 UTF-16。也就是说,它们看起来像
。因此,这可能是由该网页的混合编码引起的问题。
比较几种编码,唯一在我的机器上不会产生乱码的编码是 UTF-8。
如果它变得绝望,请在上面的代码中传递
iconvlist()
来 lapply,并查看是否有任何可能的条件适合您。Specify
UTF-8
endoding in both the call togetURL
andhtmlParse
.These locale issues are always a pain to get to the bottom of. When I type
cat(a)
(after specifyingUTF-8
encoding ingetURL
) I see that thehe.wrodpress.org
page claims to be UTF-8:<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
, but the Hebrew bits are UTF-16. That is, they look like<U+05D3><U+05E6><U+05DE><U+05D1><U+05E8>
. So it could be a problem caused by mixed oncoding of that web page.Comparing several encodings, the only one that doswn't generate gibberish on my machine is UTF-8.
If it gets desperate, pass
iconvlist()
to lapply in the above code, and see if any of the possible condings works for you.