使用 r 中的选择器小工具从地图对象获取纬度和经度



我正在使用 chrome 的选择器小工具扩展在 R 中进行数据抓取(第一次(,它使用包"rvest">这是我正在做的参考

我正在尝试从这个网站获取数据

这是我的代码

#Specifying the url for desired website to be scrapped
url <- 'http://www.magicbricks.com/property-for-sale/Multistorey-Apartment-real-estate-Mumbai'
#Reading the HTML code from the website
webpage <- read_html(url)
map_data_html <- html_nodes(webpage,'.iconMap .stop-propagation')
map <- html_text(map_data_html)
head(map)

但这只给了我作为"地图"的文本,我想访问这张地图中的纬度和长度属性。有什么建议吗?

可能不是最佳的,但这是获取纬度/纬度值的一种方法:

map_data_html <- html_nodes(webpage,'.iconMap .stop-propagation')
map = html_attr(map_data_html,"data-link") # get the data-link part
lat = as.numeric(str_match(map, "lat=(.*?)&longt")[,2]) # find the lat
lon = as.numeric(str_match(map, "longt=(.*?)&projectOr")[,2]) # find the lon

最新更新