Issues with headless browser log-in to Nike.com using Python

I’m attempting to perform some automated testing and form submissions using a headless browser in Python, but I’m struggling to get my libraries to successfully submit the login form on Nike’s website. Can anyone help me identify what might be going wrong?

import mechanize
import cookielib

cookie_jar = cookielib.LWPCookieJar()

browser_instance = mechanize.Browser()
browser_instance.set_cookiejar(cookie_jar)
browser_instance.set_handle_equiv(True)
browser_instance.set_handle_gzip(True)
browser_instance.set_handle_redirect(True)
browser_instance.set_handle_referer(True)
browser_instance.set_handle_robots(False)

response_page = browser_instance.open("http://www.nike.com/us/en_us/")

assert browser_instance.viewing_html()
print browser_instance.title()
print response_page.geturl()

html_content = response_page.read()

for form in browser_instance.forms():
    print form

# Choose the second form (index 0 is usually not the login form)
browser_instance.select_form('login-form')

# Input user credentials
browser_instance.form['email'] = '[email protected]'
browser_instance.form['password'] = 'my-secure-password'

browser_instance.submit()

When trying with robobrowser, I receive the following error:

Traceback (most recent call last):
  File "/Users/cmw/PycharmProjects/Nike_Bot/nike_bot_py.py", line 44, in <module>
    browser.submit_form(signin_form)
  File "/Library/Python/2.7/site-packages/robobrowser/browser.py", line 341, in submit_form
    response = self.session.request(method, url, **payload.to_requests(method))
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 456, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 553, in send
    adapter = self.get_adapter(url=request.url)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 608, in get_adapter
    raise InvalidSchema("No connection adapters were found for '%s'" % url)
requests.exceptions.InvalidSchema: No connection adapters were found for 'javascript:void(0);'

Could anyone shed some light on the issues I’m encountering with authentication here and suggest how I might resolve them?

that javascript:void(0) error is pretty common these days. nike’s login relies a lot on js, which mechanize struggles with. you should try using selenium with chromedriver since it runs the js properly. also, be careful with nike’s bot detection, maybe add some random delays and change your user agent too.

I’ve hit the same wall trying to automate modern websites. Nike’s login form uses dynamic JavaScript for submissions, and mechanize can’t handle that since it doesn’t execute JavaScript. That ‘javascript:void(0)’ error means the form action gets set through JavaScript instead of a static URL mechanize can follow. Most major e-commerce sites ditched simple HTML forms for JavaScript-heavy setups as a security measure. Switch to Selenium with Chrome or Firefox in headless mode - it’ll actually execute the JavaScript. Just heads up though, Nike has serious bot detection with IP tracking, behavioral analysis, and CAPTCHAs, so you’ll likely face more hurdles even with Selenium.

Mechanize is way too outdated for modern sites like Nike. Most e-commerce sites now rely heavily on JavaScript for login forms, and mechanize can’t handle that since it doesn’t execute JavaScript. That ‘javascript:void(0)’ error you’re getting confirms it - the form action is probably set through JavaScript instead of a direct URL. I’ve hit the same wall with other retail sites and switched to Selenium WebDriver with headless Chrome. You’ll need to install selenium and chromedriver, then use WebDriver to find elements and submit forms. Just heads up - Nike has pretty sophisticated anti-bot measures, so you’ll probably need proper delays and rotating user agents to avoid getting blocked.