【问题标题】:R if statement about a web page [closed]R if 关于网页的声明[关闭]
【发布时间】:2014-07-24 08:24:41
【问题描述】:

我知道我可以使用“shell.exec”从 R 打开网页。 但我想写一个循环,只有当网页打开网页 为一组网站维护一个条件。

这是一组地址中包含“value=somenumber”的网站, 我希望 R 只打开那些“somenumber”实际上有一些数据的。 没有数据的数字不会返回错误页面,而只是返回没有数据的页面。

问题是,它涉及到我需要在条件中编写的 html 元素......

这样的事情可能吗?

【问题讨论】:

    标签: r


    【解决方案1】:

    我会使用 stringr 库的 str_detect

    http://cran.r-project.org/web/packages/stringr/stringr.pdf#page.7

    假设您有一个网址列表。我只会将该列表传递给函数,如果它返回 true,那么就做你的事情。

    str_detect(urlList,"value=[:digit:]")
    

    【讨论】:

    • 您可以使用greplgrepl('value=[[:digit:]]+', urlList) 在基础中执行此操作。 (FWIW,str_detect 是对grepl 的薄包装)
    • 是的,但可读性始终很重要。当阅读代码时,str_detect 比 grepl 更有意义。
    【解决方案2】:

    这是一种使用更便携的browseURLgrep 的方法:

    x <- readLines(n=3)
    http://stackoverflow.com/questions/23840523/check-if-os-is-solaris
    http://stackoverflow.com/questions/23817341/faster-i-j-matrix-cell-fill
    http://stackoverflow.com/questions/7863710/correlating-word-proximity
    
    sapply(grep("/238", x, value=TRUE), browseURL)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-23
      • 2013-05-29
      • 1970-01-01
      • 2013-02-25
      • 2015-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多