尝试解析此 xml 文件: http://data.fcc.gov/api/block/find?latitude=48.9905&longitude=-122.2733&showall=false
rvest
/xml2
接缝无法正确识别节点:
require(rvest) #which uses xml2 internally
doc <- read_xml("http://data.fcc.gov/api/block/find?latitude=48.9905&longitude=-122.2733&showall=false")
> doc
{xml_document}
<Response>
[1] <Block FIPS="530730102002091"/>
[2] <County FIPS="53073" name="Whatcom"/>
[3] <State FIPS="53" code="WA" name="Washington"/>
尝试获取我所做的County节点 - 导致错误的原因(没有匹配项)
doc %>% xml_node("County") # Error: No matches
我还通过 read_html
和 httr::GET
结合 read_html
和 read_xml
进行了尝试。 ..
任何想法`
P.S.:示例取自此处:Parsing an XML response to a query 。我尝试通过 rvest
最佳答案
该文档有一个命名空间 xmlns
,您可以使用 xml_ns
检查它,并在您的 xpath 中使用前缀,
xml_find_one(doc, "//d1:County", xml_ns(doc))
关于xml - rvest 不提取自关闭 xml 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36166936/