让 htmlParse 与希伯来语一起工作?

发布于 2024-12-29 14:50:47 字数 629 浏览 1 评论 0原文

我希望 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铁轨上的流浪者 2025-01-05 14:50:47

在对 getURLhtmlParse 的调用中指定 UTF-8 结尾。

a <- getURL(u, .encoding = "UTF-8")
htmlParse(a, encoding = "UTF-8")

这些区域设置问题总是很难弄清楚。当我输入 cat(a) 时(在 getURL 中指定 UTF-8 编码后),我看到 he.wrodpress.org 页面声称是 UTF-8:,但是希伯来语位是 UTF-16。也就是说,它们看起来像 。因此,这可能是由该网页的混合编码引起的问题。

比较几种编码,唯一在我的机器上不会产生乱码的编码是 UTF-8。

(trees <- lapply(c("UTF-8", "UTF-16", "latin1"), function(enc)
{
  a <- getURL(u, .opts = proxy_opts, .encoding = enc)
  htmlParse(a, encoding = enc)
}))

如果它变得绝望,请在上面的代码中传递 iconvlist() 来 lapply,并查看是否有任何可能的条件适合您。

Specify UTF-8 endoding in both the call to getURL and htmlParse.

a <- getURL(u, .encoding = "UTF-8")
htmlParse(a, encoding = "UTF-8")

These locale issues are always a pain to get to the bottom of. When I type cat(a) (after specifying UTF-8 encoding in getURL) I see that the he.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.

(trees <- lapply(c("UTF-8", "UTF-16", "latin1"), function(enc)
{
  a <- getURL(u, .opts = proxy_opts, .encoding = enc)
  htmlParse(a, encoding = enc)
}))

If it gets desperate, pass iconvlist() to lapply in the above code, and see if any of the possible condings works for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文