r语言 - 从聚合器站点抓取价格



这对某些人来说可能很简单。 但我无法理解它。我正在尝试从网站中提取价格和其他信息。

链接

我正在使用 Rvest 进行抓取。我不是CS背景,所以我无法理解将使用的html节点的类输入。我正在"类似酒店"部分查找类似酒店的价格。我的代码尝试如下。请让我知道我的代码中的缺点。

    url='http://www.yatra.com/hotels/hotels-in-coorg/club-mahindra-madikeri-coorg'
    
index <- url %>%
    read_html() %>%
    html_nodes("#carousel_one")
count <- index %>%
    html_nodes("span") %>%
    html_text() %>% 
location <- counts %>%
    html_nodes("p") %>%
    html_text()
type <- counts %>%
    html_nodes("a") %>%
    html_text()

我已经转机了,但它是针对单个节点的。我想在一个命令中获取所有节点。

我的代码显然不正确。理想情况下,我正在寻求对为此类信息找到正确标签和类所涉及的方法的解释。

我已经阅读了TNC条件。

我可以得到代码,但又缺少一点逻辑。

代码为:

index <- url %>%
    read_html() %>%
    html_nodes("#container .crousel")
fetch <- index %>%
    html_nodes("span") %>%
    html_text()

最新更新