Using rvest or httr to log in to non-standard forms on a webpage

后端 未结 1 1282
春和景丽
春和景丽 2020-12-01 03:00

I am attempting to use rvest to spider a webpage that requires an email/password login on a form.

rm(list=ls())
library(rvest)

### Trying to sign into a for         


        
相关标签:
1条回答
  • 2020-12-01 03:44

    Your rvest code isn't storing the modified form, so in you're example you're just submitting the original pgform without the values being filled out. Try:

    library(rvest)
    
    url       <-"http://www.perfectgame.org/"   ## page to spider
    pgsession <-html_session(url)               ## create session
    pgform    <-html_form(pgsession)[[1]]       ## pull form from session
    
    # Note the new variable assignment 
    
    filled_form <- set_values(pgform,
      `ctl00$Header2$HeaderTop1$tbUsername` = "myemail@gmail.com", 
      `ctl00$Header2$HeaderTop1$tbPassword` = "mypassword")
    
    submit_form(pgsession,filled_form)
    

    And I now see a nice 200 status code response instead of an error. Note that because the desired submit button appears to be the first submit button, we don't need to give it as an argument, but otherwise we'd just be giving it a a string (straight quotes, not back quotes).

    0 讨论(0)
提交回复
热议问题