2

I'm trying to automate form submission on a website using robobrowser but after I submit the form I don't get the correct response instead it shows me the same page I was on. Here is my code

from robobrowser import RoboBrowser

browser = RoboBrowser()
browser.open("https://tin.tin.nsdl.com/pantan/StatusTrack.html")
form = browser.get_forms()[0]
form["ST_SEARCH_TYPE"].value = 'P'
form["ST_ACK_NUM"].value = 'Some Number'      #the ack. no.  

browser.submit_form(form)
browser.select('b')                           #shows the same page again
mrsux0r
  • 23
  • 1
  • 7
  • the problem is solved see [answer of](http://stackoverflow.com/questions/42950610/how-to-remove-attributeerror-in-robobrowser) – P.hunter Mar 22 '17 at 14:08

1 Answers1

3

you can try but specifying and passing the id of the form..

browser = RoboBrowser(id='IdOfTheForm')

if that didn't work you can try to pass the headers , by using requests like.

import requests
start = requests.session()
open = start.get('UrlOfTheWebsite')
print(open.headers)

and put the suitable headers you want by doing

start.headers = open.headers
browser = RoboBrowser(id='IdOfTheForm',session=start,history=True)

you can use parsed method if you display the contents of the response .

res = browser.submit_form(form)
print(res.parsed)

you can even specify the button name in the submit , while submitting the form. you have to inspect the name of the button

res = browser.submit_form(form, submit='NameOfTheButton')

and then try .

print(res.parsed)  

hope it works, if it doesn't provide the source code.

P.hunter
  • 1,345
  • 2
  • 21
  • 45
  • Thanks, this helps spell everything out, but what if the button does not have a name and only has an id? I've tried using the Id but get the error 'str' object has no attribute 'name' – Mwspencer Dec 22 '17 at 19:24
  • hi! did it worked without mentioning the `submit=` beacause as far I've experienced, **`providing an button name is optional`** `Robobrowser` can do the task for you, as it has already selected the form, and the submit button is in the form itself. – P.hunter Dec 23 '17 at 05:01
  • however, if the button has a href then you can just follow the link by, `browser.follow_link(hrefOfTheButton)`. Other case is that If the button is a `javascript call` it may not be able to do so, for that you have to go to the network tab, and check the request being made to the URL by clicking the button manually and then get request to the url. hope this helps. – P.hunter Dec 23 '17 at 05:05
  • thank you! I'll have to give this a go. I did run the script in python 2 and it worked without specifying the button name. But it would be nice to get it to work with python 3 since that's what I plan to build the rest of the script with. – Mwspencer Dec 25 '17 at 19:24