I am trying to use python mechanize to login into and to step through a web site whose initial page has a warning that one must click on and acknowledge in order to be able to proceed to the login page. Clicking on the link activates a javascript function that sets a cookie and sends you to the login page.
The html for the warning is
<a id='has-seen-warning' class='button' href='/login/'>I Agree</a>
and the javascript that sets the cookie is the following:
<script>
$(function(){
var agreed_to_cookie = 'agreed_to_notice';
$('#has-seen-warning').click(function(){
$.cookie(agreed_to_cookie, 'True', {expires: 365, path:'/', secure: true});
});
});
</script>
Schematically, my python code looks as follows:
import mechanize
br = mechanize.Browser()
url = "https:/blah.blah/login"
# Call login page first time
br.open(url)
# but get request to agree to notice.
# Set the cookie
br.set_cookie("agreed_to_cookie=True; expires=Sunday, 08-Dec-13 23:12:40 GMT")
# call the log in page again
br.open(url)
How should I set the cookie so that it appears that I have read and clicked on the warning?
You've replicated Set-Cookie
string wrong. Try this
// TODO: replace expiration date with your own
br.set_cookie("agreed_to_notice=True; path=/; expires=Sunday, 08-Dec-14 23:12:40 GMT; secure")