【问题标题】:using rvest to scrape a review from particular html pagein R使用 rvest 从特定的 html pagein R 中抓取评论
【发布时间】:2016-01-07 18:48:22
【问题描述】:

我正在抓取页面 tata safari discription 以获取评论和用户 cmets。我正在使用选择器小工具来获取 css 标记。到目前为止我所做的事情是:

teambhp <- read_html("http://www.team-bhp.com/forum/official-new-car-reviews/171841-tata-safari-storme-varicor-400-official-review.html")
titles <- teambhp %>% html_node("hr+ div , i ,strong u , #posts ") %>% html_text()

但它只保存了一个 title inn 标题变量。并给出如下警告。

Warning message:
In node_find_one(x$node, x$doc, xpath = xpath, nsMap = ns) :
23 matches for .//hr/following-sibling::*[name() = 'div' and (position() = 1)] | .//i | .//strong/descendant-or-self::*/u | .//*[@id = 'posts']: 
using first

我希望所有 23 个都保存在列表中。我该怎么做?

【问题讨论】:

    标签: r rvest


    【解决方案1】:

    help("html_node):

    html_node 与 html_nodes

    html_node 就像 [[ 它总是只提取一个元素。当给定一个节点列表时,html_node 总是会返回一个相同长度的列表,html_nodes 的长度可能更长或更短。

    你需要用html_nodes()替换它(注意s):

    titles <- teambhp %>% html_nodes("hr+ div , i ,strong u , #posts ") %>% html_text()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-19
      • 2016-07-09
      • 1970-01-01
      • 2022-01-15
      • 2014-10-03
      • 2020-09-13
      相关资源
      最近更新 更多