[R] How to set cookies in RCurl

Duncan Temple Lang duncan at wald.ucdavis.edu
Thu Jun 7 17:38:59 CEST 2012


Apologies for following up on my own mail, but I forgot
to explicitly mention that you will need to specify the
appropriate proxy information in the call to getURLContent().

  D.

On 6/7/12 8:31 AM, Duncan Temple Lang wrote:
> To just enable cookies and their management, use the cookiefile
> option, e.g.
> 
>   txt = getURLContent(url,  cookiefile = "")
> 
> Then you can pass this to readHTMLTable(), best done as
> 
>   content = readHTMLTable(htmlParse(txt, asText = TRUE))
> 
> 
> The function readHTMLTable() doesn't use RCurl and doesn't
> handle cookies.
> 
>    D.
> 
> On 6/7/12 7:33 AM, mdvaan wrote:
>> Hi,
>>
>> I am trying to access a website and read its content. The website is a
>> restricted access website that I access through a proxy server (which
>> therefore requires me to enable cookies). I have problems in allowing Rcurl
>> to receive and send cookies. 
>>
>> The following lines give me:
>>
>> library(RCurl)
>> library(XML)
>>
>> url <- "http://www.theurl.com"
>> content <- readHTMLTable(url)
>>
>> content
>> $`NULL`
>>                                                                                                                                                                          
>> V1
>> 1                                                                                                                                                                           
>> 2                                                                                                                                                          
>> Cookies disabled
>> 3                                                                                                                                                                           
>> 4 Your browser currently does not accept cookies.\rCookies need to be
>> enabled for Scopus to function properly.\rPlease enable session cookies in
>> your browser and try again.
>>
>> $`NULL`
>>   V1 V2 V3
>> 1         
>>
>> $`NULL`
>>                 V1
>> 1 Cookies disabled
>>
>> $`NULL`
>>   V1
>> 1   
>> 2   
>> 3  
>>
>> I have carefully read section 4.4. from this:
>> http://www.omegahat.org/RCurl/RCurlJSS.pdf and tried the following without
>> succes:
>>
>> curl <- getCurlHandle()
>> curlSetOpt(cookiejar = 'cookies.txt', curl = curl)
>>
>> Any suggestions on how to allow for cookies?
>>
>> Thanks.
>>
>> Math
>>
>> --
>> View this message in context: http://r.789695.n4.nabble.com/How-to-set-cookies-in-RCurl-tp4632693.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list