简体   繁体   English

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

[英]Get latitude and longitude from map object using selector gadget in r

I'm doing data scraping(for the first time) in R by using selectorGadget extension for chrome ,which uses the package "rvest" this is the reference from which I'm doing 我正在通过使用chrome的selectorGadget扩展来在R中进行数据抓取(第一次),它使用包“rvest” 是我正在做的参考

and from this website I'm trying to fetch data 这个网站我正在尝试获取数据

this is my code 这是我的代码

#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)

but this gives me only the text as "map" , I want to access the lat and long attribute inside this map. 但是这只给我文本作为“map”,我想访问这个map中的lat和long属性。 Any suggestion? 有什么建议吗?

Probably not optimal but this is one way to get the lat/lon values: 可能不是最优但这是获得lat / lon值的一种方法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 R 中抓取 Zillow,并使用 Selector Gadget 查找纬度和经度 - Webscraping Zillow in R, and finding Latitude and Longitude using Selector Gadget 使用地址获取 R 中的纬度和经度 - Get latitude and longitude in R using address 使用 R 中的 Leaflet 从 shapefile 获取经度和纬度 - Get longitude and latitude from a shapefile with Leaflet in R 如何使用R在地图上显示经度和纬度线? - How to display longitude and latitude lines on a map using R? 从get_map()缩放级别获取经度/纬度 - get longitude/latitude from get_map() zoom level 如何在纬度和经度中从 R 中的 PostGis 转换 Geom 对象? - How to convert Geom object from PostGis in R in latitude and longitude? 如何从R中的城市名称和国家/地区获取经度和纬度坐标? - How to get the longitude and latitude coordinates from a city name and country in R? 如何从R中的经度和纬度中获取位置名称,以获取完整的数据集? - How to get location name from latitude and longitude in R for a complete dataset? 如何从R中的州边界获取经纬度数据 - How to get latitude and longitude data from the borders of a state in R 从R中的经度和纬度点获取国家(和大陆) - Get country (and continent) from longitude and latitude point in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM