0
我试图从R中的西班牙语源中提取文本,并运行到字符编码问题,该问题未通过明确指定htmlParse
中的编码解决,因为建议使用here。字符编码错误未通过指定编码解决
library(XML)
library(httr)
url <- "http://www3.hcdn.gov.ar//folio-cgi-bin/om_isapi.dll?E1=&E11=&E12=&E13=&E14=&E15=&E16=&E17=&E18=&E2=&E3=&E5=ley&E6=&E7=&E9=&headingswithhits=on&infobase=proy.nfo&querytemplate=Consulta%20de%20Proyectos%20Parlamentarios&record={4EBB}&recordswithhits=on&softpage=Document42&submit=ejecutar%20"
doc <- htmlParse(rawToChar(GET(url)$content),encoding="windows-1252")
text <- xpathSApply(doc, "//text()[not(ancestor::script)][not(ancestor::style)][not(ancestor::noscript)][not(ancestor::form)]", xmlValue)
text[77]
第77个元素包含重音符i,它包含违规字符。第四行有一些额外的箍,我必须跳过来阅读这个来源。该文件本身声称被编码在“windows-1252”中。指定“latin1”和我尝试过的其他编码并不会更好。在我的实际应用程序中,我已经下载了许多这些文件,并使用readLines
在本地读取这些文件...并且我可以看到在将文件读入R后错误不存在,因此问题必须在htmlParse
。此外,只是接受编码错误并对其进行事后校正似乎不是一种选择,因为如果我试图将它们复制并粘贴回脚本,R甚至不会识别它正在吐出的字符。