使用rvest/httr登录

使用rvest/httr登录,r,httr,R,Httr,我正在尝试使用httr管理登录 我尝试了以下方法: username<-"email"; password<-"password" page<-html_session("https://www.crowdcube.com/login") page<-request_POST(page,url=page$response$url, body=list("em

我正在尝试使用httr管理登录

我尝试了以下方法:

username<-"email"; password<-"password"
page<-html_session("https://www.crowdcube.com/login")
page<-request_POST(page,url=page$response$url,
                       body=list("email"=username,
                                 "password"=password
                                 ,"redirect_url"="https://www.crowdcube.com"),
                     encode='json',verbose()
                       )
-> POST /login HTTP/1.1
-> Host: www.crowdcube.com
-> User-Agent: libcurl/7.64.1 r-curl/4.0 httr/1.4.1
-> Accept-Encoding: deflate, gzip
-> Cookie: AWSALBCORS=fLpF/isCxxMpnt/e2/lc1CGgyln7VFK6uuHNe94mwJKERlhwo8tgXwd0rDlEwZOGdKr6RzYFAvHhk82tgefXSBVqRE7q4le+1H02+QS+a0/eyMlT6vKMBIkpDi5k; CROWDCUBE=rc279ndia8vjstjb95g0l2pvt1; AWSALB=fLpF/isCxxMpnt/e2/lc1CGgyln7VFK6uuHNe94mwJKERlhwo8tgXwd0rDlEwZOGdKr6RzYFAvHhk82tgefXSBVqRE7q4le+1H02+QS+a0/eyMlT6vKMBIkpDi5k; __cfduid=d81f8fe2764634872724f3ea67e9226581605830327
-> Accept: application/json, text/xml, application/xml, */*
-> Content-Type: application/json
-> Content-Length: 92
-> 
>> {"email":"eeeee","password":"ppppp","redirect_url":"https://www.crowdcube.com"}

<- HTTP/1.1 302 Found
<- Date: Fri, 20 Nov 2020 00:44:39 GMT
<- Content-Type: text/html; charset=UTF-8
<- Transfer-Encoding: chunked
<- Connection: keep-alive
<- X-XSS-Protection: 1; mode=block
<- Strict-Transport-Security: max-age=15552000
<- Cache-control: no-store, no-cache
<- Cache-Control: no-cache
<- Location: /login
<- X-Request-Id: 5eaeee34-f6e1-474c-96bf-f9185226fc78
<- x-frame-options: SAMEORIGIN
<- CF-Cache-Status: DYNAMIC
<- cf-request-id: 0684b5538d00001c06f2970000000001
<- Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
<- X-Content-Type-Options: nosniff
<- Server: cloudflare
<- CF-RAY: 5f4e24cc1f471c06-OSL
<- 
-> GET /login HTTP/1.1
-> Host: www.crowdcube.com
-> User-Agent: libcurl/7.64.1 r-curl/4.0 httr/1.4.1
-> Accept-Encoding: deflate, gzip
-> Referer: https://www.crowdcube.com/login
-> Cookie: AWSALBCORS=fLpF/isCxxMpnt/e2/lc1CGgyln7VFK6uuHNe94mwJKERlhwo8tgXwd0rDlEwZOGdKr6RzYFAvHhk82tgefXSBVqRE7q4le+1H02+QS+a0/eyMlT6vKMBIkpDi5k; CROWDCUBE=rc279ndia8vjstjb95g0l2pvt1; AWSALB=fLpF/isCxxMpnt/e2/lc1CGgyln7VFK6uuHNe94mwJKERlhwo8tgXwd0rDlEwZOGdKr6RzYFAvHhk82tgefXSBVqRE7q4le+1H02+QS+a0/eyMlT6vKMBIkpDi5k; __cfduid=d81f8fe2764634872724f3ea67e9226581605830327
-> Accept: application/json, text/xml, application/xml, */*
-> Content-Type: application/json
-> 
<- HTTP/1.1 200 OK
<- Date: Fri, 20 Nov 2020 00:44:39 GMT
<- Content-Type: text/html; charset=UTF-8
<- Transfer-Encoding: chunked
<- Connection: keep-alive
<- X-XSS-Protection: 1; mode=block
<- Strict-Transport-Security: max-age=15552000
<- Cache-control: no-store, no-cache
<- Cache-Control: no-cache
<- X-Request-Id: fda74a48-75a0-4420-98b5-d565b1dc8df8
<- x-frame-options: SAMEORIGIN
<- CF-Cache-Status: DYNAMIC
<- cf-request-id: 0684b5542300001c06f7b5d000000001
<- Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
<- X-Content-Type-Options: nosniff
<- Server: cloudflare
<- CF-RAY: 5f4e24cd08101c06-OSL
<- Content-Encoding: gzip
username接受编码:deflate,gzip
->Cookie:CROWDCUBE=g59tvlaq5v5lrpsgogak9__cfduid=D18FD4953C89E16E5713CF6BA34262
->接受:application/json、text/xml、application/xml、*/*
->内容长度:0
-> 

authenticate()
功能只有在站点使用基本HTTP身份验证时才起作用,这是不可能的。从rvest版本中得到的错误是什么?如果需要支持需要跟踪状态/cookies/javascript的登录机制,则需要使用
Rselenium
。或者,您需要对特定网站的登录流进行反向工程,并在R.@MrFlick中重建它。我已经用rvest版本的输出更新了我的问题。我仍在祈祷。一个逆向工程是如何实现的呢?那么,到底有什么不适用于该版本呢?您似乎获得了一个成功的状态代码(200)。正如您所看到的,它给出了一个预期重定向的错误(据我所知是302)。事实上,它停留在登录页面上,什么也没发生。如果我跳到另一页。我看到我仍然注销。
-> POST /login HTTP/1.1
-> Host: www.crowdcube.com
-> Authorization: Basic iYmlAbWFpbC5ydToxUnVzc2
-> User-Agent: libcurl/7.64.1 r-curl/4.0 httr/1.4.1
-> Accept-Encoding: deflate, gzip
-> Cookie: CROWDCUBE=g59tvlaq5v5lrpsgogak9; __cfduid=d18fd4953c89e16e5713cff6ba34262
-> Accept: application/json, text/xml, application/xml, */*
-> Content-Length: 0
-> 
<- HTTP/1.1 302 Found
<- Date: Thu, 19 Nov 2020 23:59:49 GMT
<- Content-Type: text/html; charset=UTF-8
<- Transfer-Encoding: chunked
<- Connection: keep-alive
<- X-XSS-Protection: 1; mode=block
<- Strict-Transport-Security: max-age=15552000
<- Cache-control: no-store, no-cache
<- Cache-Control: no-cache
<- Location: /login
<- X-Request-Id: 3bf2-5d1b-483d-9f81-a78af46a
<- x-frame-options: SAMEORIGIN
<- CF-Cache-Status: DYNAMIC
<- cf-request-id: 4600000015f00a81e00000
<- Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
<- X-Content-Type-Options: nosniff
<- Server: cloudflare
<- CF-RAY: 31cc99215f0-ARN
-> POST /login HTTP/1.1
-> Host: www.crowdcube.com
-> User-Agent: libcurl/7.64.1 r-curl/4.0 httr/1.4.1
-> Accept-Encoding: deflate, gzip
-> Cookie: AWSALBCORS=fLpF/isCxxMpnt/e2/lc1CGgyln7VFK6uuHNe94mwJKERlhwo8tgXwd0rDlEwZOGdKr6RzYFAvHhk82tgefXSBVqRE7q4le+1H02+QS+a0/eyMlT6vKMBIkpDi5k; CROWDCUBE=rc279ndia8vjstjb95g0l2pvt1; AWSALB=fLpF/isCxxMpnt/e2/lc1CGgyln7VFK6uuHNe94mwJKERlhwo8tgXwd0rDlEwZOGdKr6RzYFAvHhk82tgefXSBVqRE7q4le+1H02+QS+a0/eyMlT6vKMBIkpDi5k; __cfduid=d81f8fe2764634872724f3ea67e9226581605830327
-> Accept: application/json, text/xml, application/xml, */*
-> Content-Type: application/json
-> Content-Length: 92
-> 
>> {"email":"eeeee","password":"ppppp","redirect_url":"https://www.crowdcube.com"}

<- HTTP/1.1 302 Found
<- Date: Fri, 20 Nov 2020 00:44:39 GMT
<- Content-Type: text/html; charset=UTF-8
<- Transfer-Encoding: chunked
<- Connection: keep-alive
<- X-XSS-Protection: 1; mode=block
<- Strict-Transport-Security: max-age=15552000
<- Cache-control: no-store, no-cache
<- Cache-Control: no-cache
<- Location: /login
<- X-Request-Id: 5eaeee34-f6e1-474c-96bf-f9185226fc78
<- x-frame-options: SAMEORIGIN
<- CF-Cache-Status: DYNAMIC
<- cf-request-id: 0684b5538d00001c06f2970000000001
<- Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
<- X-Content-Type-Options: nosniff
<- Server: cloudflare
<- CF-RAY: 5f4e24cc1f471c06-OSL
<- 
-> GET /login HTTP/1.1
-> Host: www.crowdcube.com
-> User-Agent: libcurl/7.64.1 r-curl/4.0 httr/1.4.1
-> Accept-Encoding: deflate, gzip
-> Referer: https://www.crowdcube.com/login
-> Cookie: AWSALBCORS=fLpF/isCxxMpnt/e2/lc1CGgyln7VFK6uuHNe94mwJKERlhwo8tgXwd0rDlEwZOGdKr6RzYFAvHhk82tgefXSBVqRE7q4le+1H02+QS+a0/eyMlT6vKMBIkpDi5k; CROWDCUBE=rc279ndia8vjstjb95g0l2pvt1; AWSALB=fLpF/isCxxMpnt/e2/lc1CGgyln7VFK6uuHNe94mwJKERlhwo8tgXwd0rDlEwZOGdKr6RzYFAvHhk82tgefXSBVqRE7q4le+1H02+QS+a0/eyMlT6vKMBIkpDi5k; __cfduid=d81f8fe2764634872724f3ea67e9226581605830327
-> Accept: application/json, text/xml, application/xml, */*
-> Content-Type: application/json
-> 
<- HTTP/1.1 200 OK
<- Date: Fri, 20 Nov 2020 00:44:39 GMT
<- Content-Type: text/html; charset=UTF-8
<- Transfer-Encoding: chunked
<- Connection: keep-alive
<- X-XSS-Protection: 1; mode=block
<- Strict-Transport-Security: max-age=15552000
<- Cache-control: no-store, no-cache
<- Cache-Control: no-cache
<- X-Request-Id: fda74a48-75a0-4420-98b5-d565b1dc8df8
<- x-frame-options: SAMEORIGIN
<- CF-Cache-Status: DYNAMIC
<- cf-request-id: 0684b5542300001c06f7b5d000000001
<- Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
<- X-Content-Type-Options: nosniff
<- Server: cloudflare
<- CF-RAY: 5f4e24cd08101c06-OSL
<- Content-Encoding: gzip