代码之家  ›  专栏  ›  技术社区  ›  Wafou Z

有没有办法过滤具有html\u属性的html\u节点?

  •  1
  • Wafou Z  · 技术社区  · 8 年前

    我开始使用R,有一个问题,我想收集一个html页面的价格列表。这是一个例子,当我问R的价格时,我能得到什么

    <h3 class="item_price" itemprop="price" content="16450">                                        16 450&nbsp;€
    </h3>
    

    我知道下面有35个价格 <h3 class="item_price" itemprop="price" content="1234">
    是否可以过滤h3元素和属性class=“item\u price”,然后请求内容属性值?

    1 回复  |  直到 8 年前
        1
  •  3
  •   Christian    8 年前

    是的,这是可能的-源:rvest::html\u attr文档

    movie <- read_html("http://www.imdb.com/title/tt1490017/")
    cast <- html_nodes(movie, "#titleCast span.itemprop")
    html_text(cast)
    html_name(cast)
    html_attrs(cast)
    html_attr(cast, "class")
    

    推荐文章