Automating Add to Cart Javascript Sequence without browser open with Python

I'm looking for a method to automate an add-to-cart process using Python WITHOUT needing to have a browser window open.

I've tried using modules such as mechanize but it does not have the functionality of directly "clicking" a web element

Currently I've been able to automate this process using Selenium but the process of having to open the browser and load web elements, photos, etc adds up to a lengthy process where time is of the essence.

An example page that I would like to automate is here :

http://store.nike.com/us/en_us/pd/kd-vi-elite-basketball-shoe/pid-972328/pgid-972324?cp=usns_twit_041214_basketball_kdelitehome

Any direction is greatly appreciated.

Answers


It seems that in the web page you listed, the "Add to Cart" button is actually a form submit button. What you can do is simulate the submission of the form by doing a POST request, with all the necessary form parameters, which you can get from all the <input> elements on the page.

A possible python implementation may be:

  1. Download the page with urllib2. You will probably have to enable cookies.
  2. Parse the page using BeautifulSoup or similar, and find all the <input> tags and their values.
  3. Construct a new POST request with all these params (while maintaining cookies).

You can use your Browser's Network sniffing capabilities to see an actual request being sent, and try to mimic it using the above tools.

Hope it helps.


Need Your Help

Reverse engineering error during migration of SqLite to MySql using MySql workbench

mysql sqlite mysql-workbench

I am migrating an SQLite database to MySql using the MySQL workbench migration wizard (Community Edition). I have downloaded the ODBC drivers for SQLite. I am able to connect to SQLite and retrie...