[英]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.