我尝试使用R
软件的RSelenium
包中的函数获取html页面的地理坐标。目标是获取值 20º27'36.1“S 54º38'03.1“W。请按照代码进行尝试。非常感谢您的帮助。
library(rvest)
library(RSelenium)
library(httpuv)
port <- httpuv::randomPort()
rD <- rsDriver(browser = c("firefox"),
verbose=TRUE,
check = FALSE,
port = port)
driver <- rD[["client"]]
urll <- "https://www.zapimoveis.com.br/lancamento/venda-apartamento-2-quartos-bairro-seminario-campo-grande-ms-46m2-id-2600496487/"
driver$navigate(urll)
politicas <- driver$findElement(using = "css",
value = "button.cookie-notifier__cta")
politicas$clickElement()
botaomapa <- driver$findElement(using = "xpath", "/html/body/main/div[1]/section/section/section[1]/button[2]")
botaomapa$clickElement()
#Attempt 1: using xpath from coordinates
coord <- driver$findElement(using="xpath", "/html/body/div/div/div/div[4]/div/div/div/div/div[1]/div")#errorrrrr
#Attempt 2: by botaomapa object
coord <- botaomapa$findElement(using="xpath", "/html/body/div/div/div/div[4]/div/div/div/div/div[1]/div")#errorrrr
#Attempt 3: by rvest package
readmap <- read_html(urll)
auxiliar <- readmap %>% html_elements("section")
auxiliar2 <- auxiliar%>%html_elements("#listing-map")
c1 <- readmap%>%html_nodes(xpath="/html/body/main/div[1]/section/section/section[2]/div/div[3]/article/iframe")#nothing
c2 <- auxiliar2%>%html_nodes(xpath="/html/body/main/div[1]/section/section/section[2]/div/div[3]/article/iframe")#nothing
c3 <- auxiliar2%>%html_nodes(xpath="/html/body/div/div/div/div[4]/div/div/div/div/div[1]/div")#nothing
1条答案
按热度按时间uqzxnwby1#
麻烦的是,Map包含在iframe中,很难访问iframe中的任何内容。看起来你可以找到iframe及其属性!iframe的
src=
属性中包含的链接包含坐标,所以你可以提取iframe链接,然后从中提取坐标。在原始代码中执行此步骤之后:
我是这么做的
下面是链接的样子:
然后可以使用正则表达式或其他方法来提取坐标
这是我把这些坐标放进谷歌时看到的,所以看起来和原来的Map一样: