名称不符合XML命名空间 [英] Name is not XML Namespace compliant
本文介绍了名称不符合XML命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试阅读此网站上的表格:
http://spacefem.com/pregnant/due.php?use=EDD&m=09&d=10&y=16
我使用rvest
,但很快就收到错误:
library(rvest)
read_html("http://spacefem.com/pregnant/due.php?use=EDD&m=09&d=10&y=16")
错误:名称扰乱程序:3tbt4d3m不符合XML命名空间[202]
此错误是什么意思,我可以做些什么来避免它?
我已经找到了导致错误的内部函数:xml2:::doc_parse_raw
。但是,xml2:::doc_parse_raw
只是对内部C代码的调用,这使得调试此问题变得更加困难。
推荐答案
另一个选项是使用htmltidy
(需要使用v0.3.0或更高版本,这意味着-截至本答案的日期-使用开发版本与CRAN版本,直到CRAN达到0.3.0+)来"清理"文档:
library(rvest)
library(htmltidy) # devtools::install_github("hrbrmstr/htmltidy")
library(httr)
URL <- "http://spacefem.com/pregnant/due.php?use=EDD&m=09&d=10&y=16"
# the site was not returning content for me w/o a more browser-like user agent
res <- GET(URL, user_agent("Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36"))
cleaned <- tidy_html(content(res, as="text", encoding="UTF-8"),
list(TidyDocType="html5"))
pg <- read_html(cleaned)
这篇关于名称不符合XML命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文