用R

用R,r,web-scraping,rselenium,R,Web Scraping,Rselenium,例如,我想从这个网页上获取数据(空间、设施、价格……和评论) 我想为此目的使用硒包。 这是我的代码: url <- "https://www.airbnb.com/rooms/9985824?guests=1&s=d2dNfFMd" library('RSelenium') pJS <- phantom() library('XML') shell.exec(paste0("C:\\Users\\Daniil\\Desktop\\R-language,Python\\fil

例如,我想从这个网页上获取数据(空间、设施、价格……和评论)

我想为此目的使用硒包。 这是我的代码:

url <- "https://www.airbnb.com/rooms/9985824?guests=1&s=d2dNfFMd"
library('RSelenium')
pJS <- phantom()
library('XML')
shell.exec(paste0("C:\\Users\\Daniil\\Desktop\\R-language,Python\\file.bat"))
Sys.sleep(10)

checkForServer()
startServer()
remDr <- remoteDriver(browserName="chrome", port=4444)
remDr$open(silent=T)

url我不确定
file.bat
中有什么内容,但您似乎主要是想收集关于清单便利设施的数据。我刚刚使用了firefox,跳过了代码中的phantomjs部分:

url <- "https://www.airbnb.com/rooms/9985824?guests=1&s=d2dNfFMd"

library('RSelenium')

checkForServer()
startServer()
remDr <- remoteDriver(browserName="firefox", port=4444)
remDr$open(silent=T)
remDr$navigate(url)

var <- remDr$findElement('css selector','#details hr+ .row')

print(var$getElementText())
[[1]]
[1] "The Space\nAccommodates: 2\nBathrooms: 1.5\nBed type: Real Bed\nBedrooms: 1\nBeds: 1\nProperty type: Apartment\nRoom type: Private room\nHouse Rules"
url
url <- "https://www.airbnb.com/rooms/9985824?guests=1&s=d2dNfFMd"

library('RSelenium')

checkForServer()
startServer()
remDr <- remoteDriver(browserName="firefox", port=4444)
remDr$open(silent=T)
remDr$navigate(url)

var <- remDr$findElement('css selector','#details hr+ .row')

print(var$getElementText())
[[1]]
[1] "The Space\nAccommodates: 2\nBathrooms: 1.5\nBed type: Real Bed\nBedrooms: 1\nBeds: 1\nProperty type: Apartment\nRoom type: Private room\nHouse Rules"