Hi Lauri. I am in the process of making some changes to the encoding in the XML package. I'll take a look over the next few days. (Not certain precisely when.)
D. Lauri Nikkinen wrote: > Hi, > > I'm trying to get data from web page and modify it in R. I have a > problem with encoding. I'm not able to get > encoding right in htmlTreeParse command. See below > >> library(RCurl) >> library(XML) >> >> site <- getURL("http://www.aarresaari.net/jobboard/jobs.html") >> txt <- readLines(tc <- textConnection(site)); close(tc) >> txt <- htmlTreeParse(txt, error=function(...){}, useInternalNodes = TRUE) >> >> g <- xpathSApply(txt, "//p", function(x) xmlValue(x)) >> head(grep(" ", g, value=T)) > > [1] "  PART-TIME EXPORT SALES ASSOCIATES (ALSO SUMMER WORK)  > Valuatum Oy  Helsinki  Ilmoitus lisätty: 31.12.2009. Viimeinen > hakupäivä: 28.02.2010" > [2] "  MSN EDITOR / ONLINE PRODUCER  Manpower Oy  Espoo  Ilmoitus > lisätty: 30.12.2009. Viimeinen hakupäivä: 15.1.2010" > [3] "  MYYNTINEUVOTTELIJA  Rand Customer Contact Oy  Helsinki  > Ilmoitus lisätty: 30.12.2009. Viimeinen hakupäivä: 30.1.2010" > [4] "  HALUATKO IT-ARKKITEHDIKSI SHANGHAIHIN?  HALUATKO > IT-ARKKITEHDIKSI SHANGHAIHIN?  Shanghai, China  Ilmoitus lisätty: > 30.12.2009. Viimeinen hakupäivä: 28.2.2010" > [5] "  HALUATKO J2EE-OHJELMISTOKEHITTÄJÄKSI SHANGHAIHIN?  > HALUATKO J2EE-OHJELMISTOKEHITTÄJÄKSI SHANGHAIHIN?  Shanghai, China >  Ilmoitus lisätty: 30.12.2009. Viimeinen hakupäivä: 28.2.2010" > [6] "  Korkeakouluharjoittelija/ työelämävalmennettava  Suomen > suurlähetystö Pristina, Kosovo  Pristina, Kosovo  Ilmoitus > lisätty: 30.12.2009. Viimeinen hakupäivä: 20.1.2010" > > This won't help: > >> txt <- readLines(tc <- textConnection(site)); close(tc) >> txt <- htmlTreeParse(txt, error=function(...){}, useInternalNodes = TRUE, >> encoding="latin1") >> g <- xpathSApply(txt, "//p", function(x) xmlValue(x)) >> head(grep(" ", g, value=T)) > > [1] "  PART-TIME EXPORT SALES ASSOCIATES (ALSO SUMMER WORK)  > Valuatum Oy  Helsinki  Ilmoitus lisätty: 31.12.2009. Viimeinen > hakupäivä: 28.02.2010" > [2] "  MSN EDITOR / ONLINE PRODUCER  Manpower Oy  Espoo  Ilmoitus > lisätty: 30.12.2009. Viimeinen hakupäivä: 15.1.2010" > [3] "  MYYNTINEUVOTTELIJA  Rand Customer Contact Oy  Helsinki  > Ilmoitus lisätty: 30.12.2009. Viimeinen hakupäivä: 30.1.2010" > [4] "  HALUATKO IT-ARKKITEHDIKSI SHANGHAIHIN?  HALUATKO > IT-ARKKITEHDIKSI SHANGHAIHIN?  Shanghai, China  Ilmoitus lisätty: > 30.12.2009. Viimeinen hakupäivä: 28.2.2010" > [5] "  HALUATKO J2EE-OHJELMISTOKEHITTÄJÄKSI SHANGHAIHIN?  > HALUATKO J2EE-OHJELMISTOKEHITTÄJÄKSI SHANGHAIHIN?  Shanghai, China >  Ilmoitus lisätty: 30.12.2009. Viimeinen hakupäivä: 28.2.2010" > [6] "  Korkeakouluharjoittelija/ työelämävalmennettava  Suomen > suurlähetystö Pristina, Kosovo  Pristina, Kosovo  Ilmoitus > lisätty: 30.12.2009. Viimeinen hakupäivä: 20.1.2010" > > Any ideas? > > Thanks, > Lauri > >> sessionInfo() > R version 2.10.0 (2009-10-26) > i386-pc-mingw32 > > locale: > [1] LC_COLLATE=Finnish_Finland.1252 LC_CTYPE=Finnish_Finland.1252 > LC_MONETARY=Finnish_Finland.1252 LC_NUMERIC=C > [5] LC_TIME=Finnish_Finland.1252 > > attached base packages: > [1] grDevices datasets splines graphics utils grid stats > methods base > > other attached packages: > [1] RDCOMClient_0.92-0 XML_2.6-0 RCurl_1.3-1 > Hmisc_3.7-0 survival_2.35-8 ggplot2_0.8.5 digest_0.4.2 > reshape_0.8.3 > [9] plyr_0.1.9 proto_0.3-8 gplots_2.7.4 > caTools_1.10 bitops_1.0-4.1 gtools_2.6.1 > gmodels_2.15.0 gdata_2.6.1 > [17] lattice_0.17-26 > > loaded via a namespace (and not attached): > [1] cluster_1.12.1 MASS_7.3-4 tools_2.10.0 > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.