我无法使用rvest获得价值

时间:2016-02-23 01:24:51

标签: r macos rvest

我试图用rvest包刮掉一组网页。它适用于大多数网页,但我可以通过使用rvest获得租金信息

url <- "http://www.trademe.co.nz/Browse/CategoryAttributeSearchResults.aspx?search=1&cid=5748&sidebar=1&132=FLAT&selected135=5&134=1&135=5&216=0&216=0&217=0&217=0&153=&122=0&122=0&123=0&123=0&59=25000&59=35000&178=0&178=0&sidebarSearch_keypresses=0&sidebarSearch_suggested=0"
rent_html <- read_html(url)

html_nodes(rent_html, "div.property-card-subtitle") # it works
html_nodes(rent_html, "div.list-view-card-price") # but this is not works

我希望在网上获得租金价值,但我不知道如何访问它。

2 个答案:

答案 0 :(得分:0)

您引用的网址不包含列表值;你已点击列表选项到达那里。将&v=List添加到网址,然后

library(rvest)
url <- "http://www.trademe.co.nz/Browse/CategoryAttributeSearchResults.aspx?search=1&cid=5748&sidebar=1&132=FLAT&selected135=5&134=1&135=5&216=0&216=0&217=0&217=0&153=&122=0&122=0&123=0&123=0&59=25000&59=35000&178=0&178=0&sidebarSearch_keypresses=0&sidebarSearch_suggested=0&v=List"
rent_html <- read_html(url)
html_nodes(rent_html, "div.list-view-card-price")

作品。

答案 1 :(得分:0)

你可以尝试

rent_prices <- rent_html %>% html_nodes("div.property-card-price") %>% html_text()
#> rent_prices
# [1] "$270 per week" "$250 per week" "$350 per week" "$300 per week"  $350 per week" "$290 per week"
# [7] "$350 per week" "$250 per week" "$330 per week" "$350 per week" "$330 per week" "$265 per week"
#[13] "$300 per week" "$300 per week" "$340 per week" "$350 per week" "$250 per week" "$325 per week"
#[19] "$320 per week" "$310 per week" "$300 per week" "$350 per week" "$270 per week" "$320 per week"
#[25] "$350 per week" "$295 per week" "$260 per week" "$305 per week" "$285 per week" "$320 per week"
#[31] "$340 per week" "$350 per week" "$300 per week" "$290 per week" "$330 per week" "$285 per week"
#[37] "$290 per week" "$270 per week"