Python Mechanize - how to send unregistered value in dropdown
I am using Python mechanics to add items to my Amazon shopping cart. On the product product page, select the "Quantity" drop-down menu in the form and submit "Add to Cart".
In the dropdown menu, you can select the quantity from 1 to 30.
The following code works for adding any product with quantities from 1 to 30. However, it does not work when I try to add quantities greater than 30, i.e. when no value is expressed in the dropdown menu).
The maximum value of 30 in the drop-down menu is an artificial limitation. In fact, you can add up to 999 items with no problem (using Firebug to send a value greater than 30 confirms this).
My question is, how can I change the following code to successfully send the NOT quantity given as the value in the dropdown menu?
import mechanize br = mechanize.Browser() br.set_handle_robots(False) br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:188.8.131.52) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] # Open an Amazon product page br.open('http://www.amazon.com/gp/product/B005KOKFR4/') # Add to Cart is form  br.select_form(nr=1) # Change quantity br.form['quantity'] = ['31'] # Submit form br.submit() print br.response().read()
If the count is between 1 and 30, the above code works. When the number is 31 or more, the error is:
mechanize._form.ItemNotFoundError: insufficient items with name '31'
source to share