[R] how to access Internet from within R?

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Fri Jun 26 08:31:46 CEST 2009


On Fri, Jun 26, 2009 at 7:21 AM, Michael<comtech.usa at gmail.com> wrote:
> Let's say I have some automation tasks where I have to fill a table
> field on a webpage, and then submit it to the server, and then obtain
> the returned value (a typical web query), how to do that in R?
>

 The RCurl package will let you construct POST requests to web pages -
this is the mechanism that the web uses to send form data to web
servers. The response comes back to the function in RCurl.

 That's if you know in advance the names of the required form fields.
Otherwise you have to do a 'GET' request to get the form (which should
be some HTML), then write some R to parse that and work out what is
what, then send a POST with your response. Sounds like you don't need
to do that if you know what the form is expecting.

 See the help for postForm in RCurl package. Basic usage is:

postForm("http://example.com/form/response.html",.params=list(name="me",text="this
is my response", vote="2")

 couldn't really be easier :)

Barry




More information about the R-help mailing list