getForm, postForm (RCurl package)

The getForm and postForm functions from the RCurl package can be used to submit forms from R. The GET and POST methods for form submission are similar but meaningfully different; check the <form> tag in the HTML of a form to determine which function to use. In the right circumstances, these functions can be useful for automating retrieval of data sets that might otherwise require a form submission for each data set.
getForm(url, …)
  • url – A character string of a URL.
  • – The GET names and their values.
postForm(url, …)
  • url – A character string of a URL.
  • – The POST names and their values.

Example. Below I sign up to be notified when OpenIntro becomes a non-profit so I can donate. After examining the HTML in the online form, I saw that there were three values (one optional) that needed to be submitted: name, email, and phone. These make up the arguments following the URL. Visit OpenIntro’s homepage or download a free PDF of the intro stat textbook, OpenIntro Statistics (paperback copies are also sold on Amazon for $9.02).
> library(RCurl)
> #=====> Sign Up To Be An OpenIntro Donor <=====#
> url    <- ""
> result <- postForm(url, name="David Diez",
+                         email="",
+                         phone="857-288-8547")
> # The result is an empty string since the page redirects
> # Otherwise postForm and getForm return the resulting HTML
> result
[1] ""
Those of you who closely follow the blog might notice that I’ve upgraded to the latest version of R since the post on getURLContent, so I no longer get a warning when I load in the RCurl package.

Leave a Reply