【问题标题】:How download files from a html form R如何从 html 表单 R 下载文件
【发布时间】:2014-07-20 05:21:44
【问题描述】:

当我按下 ctrl+s 并将此页面保存在我的网络浏览器上时

http://www.kegg.jp/kegg-bin/show_pathway?zma00944+default%3dred+cpd:C01514+cpd:C05903+cpd:C01265+cpd:C01714

我下载了 html 表单和一个包含一些 png 文件的文件夹。我对具有已知模式的 png 文件感兴趣。

有没有办法以与 R 相同的方式下载它们?

我正在尝试:

 download.file("http://www.kegg.jp/kegg-bin/show_pathway?zma00944+default%3dred+cpd:C01514+cpd:C05903+cpd:C01265+cpd:C01714","form.html", mode = "wb")

但我只下载 html 表单,而不是相关的 png。

谢谢

【问题讨论】:

  • Bioconductor pathview 软件包可能会有所帮助,请参阅 vignette
  • 嗨马丁,我试过这个包,我什至查看了代码。似乎它下载了 xml,查看代谢物坐标并为 png 着色。这很好,但对我的应用程序来说太慢了。使用 kegg url 方案要快得多。我还查看了 kegg api,似乎他们没有这个功能。

标签: html r web-services web


【解决方案1】:

这将使您顺利到达那里:

source("http://bioconductor.org/biocLite.R")
biocLite("KEGGREST")
library(png)
library(KEGGREST)
png <- keggGet(c("zma00944","default=red","cpd:C01514","cpd:C05903","cpd:C01265","cpd:C01714"), "image")
t <- tempfile()
writePNG(png, t)
browseURL(t)

不幸的是,它没有做您可能想要的红色突出显示。我不确定这是否可以通过 REST API 完成。

因此,您可能可以直接下载 URL,然后将其解析为 PNG,然后下载:

download.file("http://www.kegg.jp/kegg-bin/show_pathway?zma00944+default%3dred+cpd%3aC01514+cpd%3aC05903+cpd%3aC01265+cpd%3aC01714", "form.html")
lines <- readLines("form.html")
imgUrl <- lines[grep('img src="/', lines)]
url <- paste0("http://www.kegg.jp/", strsplit(imgUrl, '"')[[1]][2])
download.file(url, "file.png")
browseURL("file.png")

【讨论】:

  • 太好了,谢谢 Dan,很明显,png 的链接将在 html 表单上。这真的会加快我的任务...
猜你喜欢
  • 1970-01-01
  • 2018-11-23
  • 2019-05-12
  • 1970-01-01
  • 1970-01-01
  • 2015-02-26
  • 2021-12-19
  • 2019-08-02
  • 2011-01-09
相关资源
最近更新 更多