Search code examples
htmlrpostweb-scrapinghttr

I'm having trouble with sending a form using POST to retrieve data in R


I'm having trouble collecting doctors from https://www.uchealth.org/providers/. I've found out it's a POST method but with httr I can't seem to create the form. Here's what I have

url = url = 'https://www.uchealth.org/providers/'
formA = list(title = 'Search', onClick = 'swapForms();', doctor-area-of-care-top = 'Cancer Care')
formB = list(Search = 'swapForms();', doctor-area-of-care = 'Cancer Care')
get = POST(url, body = formB, encode = 'form')

I'm fairly certain formB is the correct one. However, I can't test it since I yield an error when trying to make the list. I believe it is because you can't use "-" characters when naming although I could be wrong on that. Could somebody help please?


Solution

  • I am unable to comment properly but try this to create an list. Code below worked for me.

    library(httr)
    url =  'https://www.uchealth.org/providers/'
    formB = list(Search = 'swapForms();', `doctor-area-of-care` = 'Cancer Care')
    get = POST(url, body = formB, encode = 'form')
    

    When you are creating names with spaces or some other special character you have to put it into the operator above.