你可以抓住它告訴onclick
處理程序做什麼,只是直接將數據嵌入<li>
標籤中的數據:
library(httr)
library(rvest)
library(purrr)
library(stringr)
URL <- "http://olx.pl/oferta/pokoj-1-os-bielany-encyklopedyczna-CID3-IDdX6wf.html#c1c0e14c53"
pg <- read_html(URL)
html_nodes(pg, "li.rel") %>% # get the 'special' <li> tags
html_attrs() %>% # extract all the attrs (they're non-standard)
flatten_chr() %>% # list to character vector
keep(~grepl("rel \\{", .x)) %>% # only want ones with 'hidden' secret data
str_extract("(\\{.*\\})") %>% # only get the data
unique() %>% # there are duplicates
map_df(function(x) {
path <- str_match(x, "'path':'([[:alnum:]]+)'")[,2] # extract out the path
id <- str_match(x, "'id':'([[:alnum:]]+)'")[,2] # extract out the id
ajax <- sprintf("http://olx.pl/ajax/misc/contact/%s/%s/", path, id) # make the AJAX/XHR URL
value <- content(GET(ajax))$value # get the data
data.frame(path=path, id=id, value=value, stringsAsFactors=FALSE) # make a data frame
})
## Source: local data frame [3 x 3]
##
## path id value
## (chr) (chr) (chr)
## 1 phone dX6wf 503 155 744
## 2 skype dX6wf e.bobruk
## 3 communicator dX6wf 7686136
做完這一切,我很失望網站沒有更好的服務/使用條款。很明顯,他們真的不希望你刮這些數據。
您是否嘗試過RSelenium? – Jota