2016-02-23 72 views
0

我试图用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 

我想在网络上的租金价格的价值得到租赁费的信息,但我不知道如何访问它。

+0

'html_nodes(rent_html, “div.property卡价格容器”)'? –

+0

我只想获得[div.list-view-card-price] inner [div.property-card-price-containe]的信息。这是不可能的吗? –

回答

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" 
+1

哇!有用!!你如何找到* property-card-price *?我无法在html代码中找到它。 –

+0

你能解释一下更多细节吗?我也使用Firefox检查器选项,但我仍然无法找到** property-card-price **。价格是** div.list-view-card-price **设置的,正如我上面所说的。 –

+0

您可能处于该页面的“列表视图”模式。点击页面右上方有四个方块的图标,切换到“图库视图”模式。那么它不应该很难找到。 – RHertel

0

您引用的URL不包含列表值;你已经点击了列表选项来达到目的。将&v=List添加到URL中,然后

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") 

的作品。

+0

感谢乔纳森,但它的结果并不完美,代表价格与日期在一起。没有日期,没有办法只访问价格价值吗?或者我应该再次提取它的信息? –

+0

如果你想对它做额外的处理,那么你可以做到这一点。 'html_nodes'提取整个元素。 –