Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. curl --dump-header cook.txt ^
  2. --data "RURL=http=//www.example.com/r&user=bob&password=hello" ^
  3. --user-agent "Mozilla/5.0" ^
  4. http://www.example.com/login
  5.  
  6. HTTP/1.1 302 Found
  7. Date: Thu, ******
  8. Server: Microsoft-IIS/6.0
  9. SERVER: ******
  10. X-Powered-By: ASP.NET
  11. X-AspNet-Version: 1.1.4322
  12. Location: ******
  13. Set-Cookie: Cookie1=; domain=******; expires=****** ******
  14. ******
  15. ******
  16. Cache-Control: private
  17. Content-Type: text/html; charset=iso-8859-1
  18. Content-Length: 189
  19.  
  20. library(httr)
  21.  
  22. POST("http://www.example.com/login",
  23. body= list(RURL="http=//www.example.com/r",
  24. user="bob", password="hello"),
  25. user_agent("Mozilla/5.0"))
  26.  
  27. Response [http://www.example.com/error]
  28. Status: 411
  29. Content-type: text/html
  30. <h1>Length Required</h1>
  31.  
  32. library(RCurl)
  33. curl <- getCurlHandle()
  34. curlSetOpt(cookiejar="/tmp/cookies.txt", curl=curl)
  35. postForm("http://example.com/login", login="mylogin", passwd="mypasswd", curl=curl)
  36. getURL("http://example.com/anotherpage", curl=curl)
  37.  
  38. GET("http://httpbin.org/cookies/set?a=1")
  39. # Response [http://httpbin.org/cookies]
  40. # Status: 200
  41. # Content-type: application/json
  42. # {
  43. # "cookies": {
  44. # "a": "1"
  45. # }
  46. # }
  47.  
  48. GET("http://httpbin.org/cookies")
  49. # Response [http://httpbin.org/cookies]
  50. # Status: 200
  51. # Content-type: application/json
  52. # {
  53. # "cookies": {
  54. # "a": "1"
  55. # }
  56. # }
  57.  
  58. ### RCurl login and browse private pages ###
  59.  
  60. library("RCurl")
  61.  
  62. loginurl ="http=//www.*****"
  63. mainurl ="http=//www.*****"
  64. agent ="Mozilla/5.0"
  65.  
  66. #User account data and other login pars
  67. pars=list(
  68. RURL="http=//www.*****",
  69. Username="*****",
  70. Password="*****"
  71. )
  72.  
  73. #RCurl pars
  74. curl = getCurlHandle()
  75. curlSetOpt(cookiejar="cookiesk.txt", useragent = agent, followlocation = TRUE, curl=curl)
  76. #or simply
  77. #curlSetOpt(cookiejar="", useragent = agent, followlocation = TRUE, curl=curl)
  78.  
  79. #post login form
  80. web=postForm(loginurl, .params = pars, curl=curl)
  81.  
  82. #go to main url with real data
  83. web=getURL(mainurl, curl=curl)
  84.  
  85. #parse/print content of web
  86. #..... etc. etc.
  87.  
  88.  
  89. #This has the side effect of saving cookie data to the cookiejar file
  90. rm(curl)
  91. gc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement