我正在尝试从此网页访问纬度和经度数据 http://chicago.craigslist.org/search/apa?query=pilsen&zoomToPosting=&srchType=A&minAsk=&maxAsk=&bedrooms=&housing_type=
源代码如下所示:
<p class="row" data-latitude="41.8500405654737" data-longitude="-87.6500521703668" data-pid="4005695169"> <a href="/chc/apa/4005695169.html" class="i"></a> <span class="pl"> <span class="star"></span> <span class="date">Aug 16</span> <a href="/chc/apa/4005695169.html">UIC/ Medical Dist /Pilsen</a> </span> <span class="l2"> <span class="price">$850</span> / 1br - <span class="pnr"> <small> (Pilsen)</small> <span class="px"> <span class="p"> <a href="#" class="maptag" data-pid="4005695169">map</a></span></span> </span> </span></p>
我是 XPATH 的新手,我想知道是否可以使用它和 XML 包来获取数据。
我试过了:
require(XML)
url <- "http://chicago.craigslist.org/search/apaquery=pilsen&zoomToPosting=&srchType=A&minAsk=&max Ask=&bedrooms=&housing_type="
doc <- htmlParse(url)
latitude <- xpathApply(doc,path="//p[@data-latitude]",fun=xmlValue)
这给了我 p 标签的内容:
[[1]]
[1] "Aug 16 AMAZING Pilsen 2bed SHOWING TODAY @6:30pm $695 / 2br - 725ft² -
我想知道如何访问形成像纬度这样的段落标签的信息(例如 41.8500405654737) 感谢您的帮助!