Rselenium xpath无法保存响应

时间:2018-04-15 16:39:52

标签: r xml curl rselenium

我正试图从https://www.vinmonopolet.no/获得股票 例如这款酒https://www.vinmonopolet.no/vmp/Land/Chile/Gato-Negro-Cabernet-Sauvignon-2017/p/295301

使用Rselenium

library('RSelenium')
    rD=rsDriver()
    remDr =rD[["client"]]
    remDr$navigate("https://www.vinmonopolet.no/vmp/Land/Chile/Gato-Negro-Cabernet-Sauvignon-2017/p/295301")
    webElement = remDr$findElement('xpath', '//*[@id="product_2953010"]/span[2]')
    webElement$clickElement()

它将呈现Response

但如何储存呢? Full XML

2 个答案:

答案 0 :(得分:0)

也许你正在寻找rvest

library(rvest, tidyverse)

url <- "https://www.vinmonopolet.no/vmp/Land/Chile/Gato-Negro-Cabernet-Sauvignon-2017/p/295301"

page <- read_html(url)
stock <- page %>%
  html_nodes(".product-stock-status div") %>% 
  html_text()

stock.df <- data.frame(url,stock)

提取号码使用

stock.df <- stock.df %>% 
  mutate(stock=as.numeric(gsub(".*?([0-9]+).*", "\\1", stock)))

答案 1 :(得分:0)

只需发送正确的普通请求就可以了,不需要R

https://www.vinmonopolet.no/vmp/store-pickup/1101/pointOfServices?locationQuery=0661&cartPage=false&entryNumber=0&CSRFToken=718228c1-1dc1-41cd-a35e-23197bed7b0c