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:1.9.0.1) 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 [1]
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'

      

+3


source to share


1 answer


It seems that even when I try to manually put a number greater than 30 it doesn't let me. Are you sure up to 999 is allowed? Perhaps 30 is the maximum order size?



0


source







All Articles