Submit a form using POST with g-recaptcha-response argument

前端 未结 1 1616
醉话见心
醉话见心 2021-01-12 03:04

I want to submit a form from following web page: http://www.hzzo-net.hr/statos_OIB.htm

First, I use 2captcha service to bypass recaptcha:

# parameter         


        
相关标签:
1条回答
  • 2021-01-12 03:57

    If you inspect the HTML you'll see that the form's action is ../cgi-bin/statos_OIB.cgi, which means that the form is submitted to http://www.hzzo-net.hr/cgi-bin/statos_OIB.cgi, so you must use that URL.

    Also, after some testing I discovered that the server returns a 500 response, unless a valid Referer (http://www.hzzo-net.hr/statos_OIB.htm) is provided.

    I'm not familiar with R, but I can provide an example in Python, using the requests library.

    import requests
    
    url = "http://www.hzzo-net.hr/cgi-bin/statos_OIB.cgi"
    hzzo_response = 'your token'
    data = {
        'upoib': '93335620125', 
        'g-recaptcha-response': hzzo_response
    }
    headers = {'referer': 'http://www.hzzo-net.hr/statos_OIB.htm'}
    r = requests.post(url, data=data, headers=headers)
    html = r.text
    
    print(html)
    

    After studying the httr docs I managed to 'translate' the above code in R. The code produces correct results if a valid token is supplied.

    library(httr)
    
    url <- "http://www.hzzo-net.hr/cgi-bin/statos_OIB.cgi"
    hzzo_response <- "your token"
    parameters <- list(
      'upoib' = "93335620125", 
      'g-recaptcha-response' = hzzo_response
    )
    test <- POST(
      url,
      body = parameters, 
      add_headers(Referer = 'http://www.hzzo-net.hr/statos_OIB.htm'),
      encode = "form",
      verbose()
    )
    html <- content(test, 'text', encoding = 'UTF-8')
    
    print(html)
    
    0 讨论(0)
提交回复
热议问题