
Hi All,

First method:-
>library(XML)

>theurl <- "http://home.sina.com"
>download.file(theurl, "tmp.html")

>txt <- readLines("tmp.html")

>txt <- htmlTreeParse(txt, error=function(...){}, useInternalNodes = 
TRUE)

>g <- xpathSApply(txt, "//p", function(x) xmlValue(x))

>head(grep(" ", g, value=T))


[1] "ç¹é«” | ç°¡é«” | ENGLISH"                               "å¥³æ†²å…µç«™å´— é›»é¢¨æ‰‡ä¼ºå€™"                        
[3] "é¬¼å‰ƒé ­ç¾Žå°‘å¥³ é¸ç¾Žçˆ†å†·ç¨±å¾Œ(åœ–)"              "ï¼ˆåœ‹éš›ï¼‰æ€§æ„Ÿèˆªç©ºå»£å‘Š ä¿„åŠè£¸ç©ºå§æ´—é£›æ©Ÿ"
[5] " å››æµ·åŒå¿ƒæ…¶é›™åä¹‹å°ç£ç’°å³¶æ¸¸"                "é è³¼æ©Ÿç¥¨! é€æ‚ æ¸¸å¡! æŠ½äº”æ˜Ÿé…’åº—å’Œæ©Ÿç¥¨!"  



SecondMethod:-
>library(RCurl)

>theurl <- getURL("http://home.sina.com",encoding='GB2312')

>Encoding(theurl)

[1]"unknown"

>txt <- readLines(con=textConnection(theurl),encoding='GB2312')
>txt[5:10] #show the lines which occurred encoding problem.
[1] "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
[2] "<title>SINA.com US æ–°æµªç¶² -åŒ—ç¾Ž</title>"
[3] "<meta name=\"Keywords\" content=\"åŒ—ç¾Žæ–°æµª, æ–°æµªåŒ—ç¾Žç«™, ç¾Žåœ‹ä¸­æ–‡ç¶², åŒ—ç¾Žä¸­æ–‡ç¶²ç«™,è¯äººç¶²ç«™, SINA, US, News, Chinese, Asia\" />"
[4] "<meta name=\"Description\" content=\"åŒ—ç¾Žåœ°å€æœ€å¤§çš„ä¸­æ–‡ç¶²çµ¡åª’é«”, ç‚ºæµ·å¤–è¯äºº24å°æ™‚ä¸é–“æ–·æä¾æµ·é‡è³‡è¨Š, å…§å®¹åŒ…æ‹¬æœ€æ–°æ–°èž, å¨›æ¨‚è¨Šæ¯, å¯¦ç”¨ç§»æ°‘è³‡è¨Š, è‚¡å¸‚åŒ¯å¸‚è²¡ç¶“ä¿¡æ¯, é«˜äººæ°£BBS, é¢å‘å—ç¾Žè¯äººçš„äº¤å‹å¹³å°ç­‰.\" />"
[5]""                                                                                                                                                                                                                                                                                
[6] "<link rel=\"stylesheet\" type=\"text/css\" href=\"http://ui.sina.com/assets/css/style_home.css\" />"

i am trying to read data from a Chinese language website, but the Chinese characters always unreadable, may I know if any good idea to cope such encoding problem in RCurl and XML?


Regards,
Ryusuke
 		 	   		  
_________________________________________________________________


	[[alternative HTML version deleted]]

