如何获取最新的 RStudio 版本

Ada*_*ski 5 bash xpath r rstudio

我正在努力编写一个脚本,该脚本会以某种方式抓取https://www.rstudio.com/products/rstudio/download/最新 RStudio 版本的编号,下载并安装它。

由于我是 R 程序员,所以我开始使用rvestpackage.json编写 R 脚本。我设法抓取了 RStudio 服务器的下载链接,但我仍然无法获得 RStudio 本身。

这是用于获取适用于 Ubuntu 的 64 位 RStudio 服务器的下载链接的 R 代码。

if(!require('stringr')) install.packages('stringr', Ncpus=8, repos='http://cran.us.r-project.org')
if(!require('rvest')) install.packages('rvest', Ncpus=8, repos='http://cran.us.r-project.org')

xpath<-'//code[(((count(preceding-sibling::*) + 1) = 3) and parent::*)]'
url<-'https://www.rstudio.com/products/rstudio/download-server/'
thepage<-xml2::read_html(url)
the_links_html <- rvest::html_nodes(thepage,xpath=xpath)
the_links <- rvest::html_text(the_links_html)
the_link <- the_links[stringr::str_detect(the_links, '-amd64\\\\.deb')]
the_r_uri<-stringr::str_match(the_link, 'https://.*$')
cat(the_r_uri)
Run Code Online (Sandbox Code Playgroud)

不幸的是,RStudio 桌面下载页面具有完全不同的布局,我在这里无法使用相同的方法。

有人可以帮我弄这个吗?我不敢相信,世界上所有的数据科学家都手动升级了他们的 RStudio!


有一个更简单的脚本版本,它读取 RStudio 服务器的版本。bash 版本:

RSTUDIO_LATEST=$(wget --no-check-certificate -qO- https://s3.amazonaws.com/rstudio-server/current.ver)
Run Code Online (Sandbox Code Playgroud)

或 R 版本:

scan('https://s3.amazonaws.com/rstudio-server/current.ver', what = character(0))
Run Code Online (Sandbox Code Playgroud)

但是 RStudio-desktop 的版本仍然让我望而却步。

Spa*_*man 2

如果您使用版本字符串查询 RStudio,check_for_update您将获得更新版本以及获取版本的 URL:

https://www.rstudio.org/links/check_for_update?version=1.0.0

update-version=1.0.153&update-url=https%3A%2F%2Fwww.rstudio.com%2Fproducts%2Frstudio%2Fdownload%2F&update-message=RStudio%201.0.153%20is%20now%20available%20%28you%27re% 20使用%201.0.0%29&更新紧急=0

看这里:

https://github.com/rstudio/rstudio/blob/54cd3abcfc58837b433464c793fe9b03a87f0bb4/src/cpp/session/modules/SessionUpdates.R

如果你真的想从下载页面上抓取它,那么我会在第一个类“下载”的第一个中获取href它,然后解析出“RStudio-”和“.exe”之间的三个点分隔的数字”。RStudio 在所有平台上发布版本,因此从 Windows 下载中获取它应该足够了。<a><td><table>

> url = "https://www.rstudio.com/products/rstudio/download/"
> thepage<-xml2::read_html(url)
> html_node(thepage, ".downloads td a") %>% html_attr("href")
[1] "https://download1.rstudio.org/RStudio-1.0.153.exe"
Run Code Online (Sandbox Code Playgroud)