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?