<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:10pt"><div style="font-size: 10pt;"><span style="background-color: transparent;">Walmes,</span></div><div style="font-size: 13px; color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; background-color: transparent; font-style: normal;"><span style="background-color: transparent;"><br></span></div><div style="font-size: 13px; color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; background-color: transparent; font-style: normal;"><span style="background-color: transparent;">Colocando a opção </span><span style="background-color: transparent; font-family: 'Courier New', courier, monaco, monospace, sans-serif;">encoding = "utf-8"</span><span style="background-color: transparent;"> na função htmlTreeParse funciona para mim. </span><br></div><div style="font-size: 13px; color: rgb(0, 0, 0); font-family:
 'Courier New', courier, monaco, monospace, sans-serif; background-color: transparent; font-style: normal;"><span><br></span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 13px;">> library(XML)</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 13px;">> </span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 13px;">> # lê a página do vídeo com esse endereço</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 13px;">> lines <- readLines("http://www.youtube.com/watch?v=P3m6rJR2yDI")</span></div><div style="background-color: transparent;"><span
 style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 13px;">> </span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 13px;">> # organiza</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 13px;">> h <- htmlTreeParse(lines, asText=TRUE, useInternalNodes=TRUE, encoding = "utf-8")</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 13px;">></span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 13px;">> # pega o título do vídeo</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New',
 courier, monaco, monospace, sans-serif; font-size: 13px;">> n <- unlist(getNodeSet(doc=h, path="//title", fun=xmlValue))</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 13px;">> n</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 13px;">[1] "Matemática - Estatística: Conceito e frequências - YouTube"</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 13px;">> iconv(n, from="utf-8")</span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 13px;"></span></div><div style="background-color: transparent;"><span style="font-family: 'Courier New', courier,
 monaco, monospace, sans-serif; font-size: 13px;">[1] "Matemática - Estatística: Conceito e frequências - YouTube"</span></div><div style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"><br></div><div style="font-size: 13px; font-family: arial, helvetica, sans-serif; color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><br></div><div style="font-size: 13px; font-family: arial, helvetica, sans-serif; color: rgb(0, 0, 0); background-color: transparent; font-style: normal;">Att.,</div><div style="font-size: 13px; font-family: arial, helvetica, sans-serif; color: rgb(0, 0, 0); background-color: transparent; font-style: normal;">Rubem</div><div style="font-size: 13px; font-family: arial, helvetica, sans-serif; color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><br></div>  <div style="font-size: 10pt; font-family: arial, helvetica, sans-serif;"> <div style="font-family: 'times new roman', 'new york',
 times, serif; font-size: 12pt;"> <div dir="ltr"> <hr size="1">  <font size="2" face="Arial"> <b><span style="font-weight:bold;">De:</span></b> walmes . <walmeszeviani@gmail.com><br> <b><span style="font-weight: bold;">Para:</span></b> r-br@listas.c3sl.ufpr.br <br> <b><span style="font-weight: bold;">Enviadas:</span></b> Sexta-feira, 7 de Junho de 2013 9:49<br> <b><span style="font-weight: bold;">Assunto:</span></b> [R-br] encoding de páginas web readLines XML<br> </font> </div> <div class="y_msg_container"><br><div id="yiv1805791096"><font face="trebuchet ms,sans-serif">Saudações,<br><br>Estou fazendo um estudo com vídeos do youtube. A partir dos links eu retiro informações deles, como o título. No entanto, não estou conseguindo acertar o encoding, seja para ler corretamente a página ou para tranformar as strings após a leitura. Com o CMR abaixo eu leio o código de um vídeo do youtube e pego seu título, o problema é que os acentos
 não são corretamente representados, e eu preciso que sejam. Tentei atribuir um encoding na readLines() mas nenhum dos usados (latin1 e utf-8) funcionaram. Tentei usar a iconv() mas sem sucesso. Uso ubuntu 12.04. Sessão R está no CMR.<br>
<br><span style="font-family: 'courier new', monospace;">library(XML)<br><br># lê a página do vídeo com esse endereço<br>lines <- readLines("<a rel="nofollow" target="_blank" href="http://www.youtube.com/watch?v=P3m6rJR2yDI">http://www.youtube.com/watch?v=P3m6rJR2yDI</a>")<br>
# lines <- readLines("<a rel="nofollow" target="_blank" href="http://www.youtube.com/watch?v=P3m6rJR2yDI">http://www.youtube.com/watch?v=P3m6rJR2yDI</a>", encoding=?)<br><br># organiza<br>h <- htmlTreeParse(lines, asText=TRUE, useInternalNodes=TRUE)<br>
summary(h)<br><br># pega o título do vídeo<br>n <- unlist(getNodeSet(doc=h, path="//title", fun=xmlValue))<br>n<br><br>Encoding(n)<br><br># retira os caracteres estranhos substituindo por vazio<br>iconv(nap, from="UTF-8", to="ASCII", sub="")<br>
# iconv(n, from=?, to=?)<br><br><b><span style="color:rgb(204,0,0);"># Como sai<br># "Matemática - Estatística: Conceito e frequências - YouTube"<br><br># Como eu gostaria<br># "Matemática - Estatística: Conceito e frequências - YouTube"</span></b><br>
</span><br><span style="font-family: 'courier new', monospace;">## > sessionInfo()<br>## R version 3.0.1 (2013-05-16)<br>## Platform: i686-pc-linux-gnu (32-bit)<br><br>## locale:<br>##  [1] LC_CTYPE=pt_BR.UTF-8       LC_NUMERIC=C              <br>
##  [3] LC_TIME=pt_BR.UTF-8        LC_COLLATE=pt_BR.UTF-8    <br>##  [5] LC_MONETARY=pt_BR.UTF-8    LC_MESSAGES=pt_BR.UTF-8   <br>##  [7] LC_PAPER=C                 LC_NAME=C                 <br>##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            <br>
## [11] LC_MEASUREMENT=pt_BR.UTF-8 LC_IDENTIFICATION=C       <br><br>## attached base packages:<br>## [1] stats     graphics  grDevices utils     datasets  methods   base     <br><br>## other attached packages:<br>## [1] XML_3.96-1.1<br>
<br>## loaded via a namespace (and not attached):<br>## [1] compiler_3.0.1 tools_3.0.1   <br>## > <br></span><br>Alguém saberia solucionar esse problema?<br>Desde já grato.<br><br>Walmes.<br><br clear="all"></font><div>
<span style="font-family: 'trebuchet ms', sans-serif;">==========================================================================</span><br style="font-family: 'trebuchet ms', sans-serif;"><span style="font-family: 'trebuchet ms', sans-serif;">Walmes Marques Zeviani</span><br style="font-family: 'trebuchet ms', sans-serif;">
<span style="font-family: 'trebuchet ms', sans-serif;">LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W)</span><br style="font-family: 'trebuchet ms', sans-serif;"><span style="font-family: 'trebuchet ms', sans-serif;">Departamento de Estatística - Universidade Federal do Paraná</span><br style="font-family: 'trebuchet ms', sans-serif;">
<span style="font-family: 'trebuchet ms', sans-serif;">fone: (+55) 41 3361 3573</span><br style="font-family: 'trebuchet ms', sans-serif;"><span style="font-family: 'trebuchet ms', sans-serif;">VoIP: (3361 3600) 1053 1173</span><br style="font-family: 'trebuchet ms', sans-serif;">
<span style="font-family: 'trebuchet ms', sans-serif;">e-mail: <a rel="nofollow" ymailto="mailto:walmes@ufpr.br" target="_blank" href="mailto:walmes@ufpr.br">walmes@ufpr.br</a><br>skype: walmeszeviani<br style="font-family: 'trebuchet ms', sans-serif;"></span><span style="font-family: 'trebuchet ms', sans-serif;">twitter: @walmeszeviani</span><br style="font-family: 'trebuchet ms', sans-serif;">
<span style="font-family: 'trebuchet ms', sans-serif;">homepage: <a rel="nofollow" target="_blank" href="http://www.leg.ufpr.br/~walmes">http://www.leg.ufpr.br/~walmes</a></span><br style="font-family: 'trebuchet ms', sans-serif;"><span style="font-family: 'trebuchet ms', sans-serif;">linux user number: 531218</span><br style="font-family: 'trebuchet ms', sans-serif;">
<span style="font-family: 'trebuchet ms', sans-serif;">==========================================================================</span></div></div><br>_______________________________________________<br>R-br mailing list<br><a ymailto="mailto:R-br@listas.c3sl.ufpr.br" href="mailto:R-br@listas.c3sl.ufpr.br">R-br@listas.c3sl.ufpr.br</a><br><a href="https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br" target="_blank">https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br</a><br>Leia o guia de postagem (<a href="http://www.leg.ufpr.br/r-br-guia" target="_blank">http://www.leg.ufpr.br/r-br-guia</a>) e forneça código mínimo reproduzível.<br><br></div> </div> </div>  </div></body></html>