rvest 不提取自闭 xml-nodes
rvest does not extract self-closing xml-nodes
正在尝试解析此 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 文件: 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))