【问题标题】:Exculding multiple Nodes RVest排除多个节点 RVest
【发布时间】:2017-11-13 20:12:14
【问题描述】:

我正在抓取报纸上的文章,并且正在努力弄清楚如何排除多个节点。 R 帮助说:not() 接受一系列简单的选择器。我尝试了以下

zeit_url <- read.html("http://www.zeit.de/wissen/gesundheit/2017-09/aids-hiv-neuinfektionen-europa-virus-gesundheit)

article <- zeit_url %>%
    html_nodes('.article-page>:not(.ad-container, .cardstack)') %>%
    html_text()

不能用逗号分隔两个节点。有什么建议可以正确指定:not() 中的选择器序列吗?

我花了很多时间寻找答案,但我是 R(和 HTML)的新手,所以如果这是显而易见的事情,我感谢你的耐心。

【问题讨论】:

  • 现在您的代码缺少右引号和括号,并且该页面上没有名为 article-age 的类,因此不清楚您要获取什么。
  • 对不起,我在我的代码中更正了!

标签: r web-scraping rvest


【解决方案1】:
library(rvest)
zeit_url <- read_html("http://www.zeit.de/wissen/gesundheit/2017-
            09/aids-hiv-neuinfektionen-europa-virus-gesundheit")

article <- zeit_url %>%
           html_nodes(".article-page>:not(.ad-container):not(.cardstack)") %>%
           html_text()  

【讨论】:

  • 很高兴为您提供帮助。你很亲密。如果这对您有用,请接受答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多