我正在尝试解析从ZillowR API返回的列表。它确实看起来像XML,但我只得到试图解析它的错误。我想把它放在单行数据框中,某些节点是列名,它们的值是值。数据框将包含zipId,地址,邮政编码,最后售价等列...
> class(listings)
[1] "list"
> class(listings$response)
[1] "XMLNode" "RXMLAbstractNode" "XMLAbstractNode" "oldClass"
> listings$response
<response>
<results>
<result>
<zpid>106502569</zpid>
<address>
<street>2914 N Lincoln Rd</street>
<zipcode>49431</zipcode>
<city>Ludington</city>
<state>MI</state>
<latitude>44.009122</latitude>
<longitude>-86.439803</longitude>
</address>
<FIPScounty>26105</FIPScounty>
<useCode>SingleFamily</useCode>
<taxAssessmentYear>2015</taxAssessmentYear>
<taxAssessment>64400.0</taxAssessment>
<yearBuilt>1992</yearBuilt>
<lotSizeSqFt>217800</lotSizeSqFt>
<finishedSqFt>1500</finishedSqFt>
<bathrooms>2.0</bathrooms>
<bedrooms>2</bedrooms>
<lastSoldDate>12/05/2016</lastSoldDate>
<lastSoldPrice currency="USD">1</lastSoldPrice>
<zestimate>
<amount currency="USD">153718</amount>
<last-updated>12/05/2016</last-updated>
<oneWeekChange deprecated="true"/>
<valueChange duration="30" currency="USD">-1443</valueChange>
<valuationRange>
<low currency="USD">141421</low>
<high currency="USD">170627</high>
</valuationRange>
<percentile>0</percentile>
</zestimate>
<localRealEstate/>
</result>
</results>
</response>
当我试图解析它时......
> library(xml2)
> xml_find_all(listings$response, "zpid")
Error in UseMethod("xml_find_all") :
no applicable method for 'xml_find_all' applied to an object of class "XMLNode"
> xml_name(listings$response)
Error in UseMethod("xml_name") :
no applicable method for 'xml_name' applied to an object of class "XMLNode"
> xmlParse(listings$response)
Error in file.exists(file) : invalid 'file' argument
提前致谢, 史蒂夫