https://github.com/cran/XML
Raw File
Tip revision: ff04f6f490ade410b75a8fa3105db027edae510f authored by ORPHANED on 17 January 2020, 09:26:36 UTC
version 3.99-0.1
Tip revision: ff04f6f
redirection.R
# This is an example of downloading data that is accessible via a text file
# that is identified via a link in an HTML document that is returned from
# a form submission.
# The original form is available via the SWISSPROT site which is redirected
# to www.expasy.org.
#
#  This example illustrates the use of the FOLLOWLOCATION options in libcurl and hence
#  RCurl.
#
# The example was raised  by Linda Tran at UC Davis.
# Works as of May 12, 2006
#

tt = getForm("http://www.expasy.org/cgi-bin/search",
               db = "sptrde", SEARCH = "fmod_bovin",
              .opts = list("FOLLOWLOCATION" = TRUE))

# Then, find the link node <a> which has "raw text"
# in the text of the link

h = function() {
   link = ""
   a = function(node, ...) {
     v = xmlValue(node)
     if(length(grep("raw text", v)))
       link <<- xmlGetAttr(node, "href")

     node
   }
   list(a = a, .link = function() link)
}

a = h()
htmlTreeParse(tt, asText = TRUE, handlers = a)
a$.link()

u = paste("http://www.expasy.org", a$.link(), sep = "")

getURL(u)
back to top