Skip to content Skip to sidebar Skip to footer

Set Mechanize To Accept Cookies

I am trying to use mechanize to retrieve some data from a website to automatize searching for a flat (no spamming) However, when I send a request to the site, the response has the

Solution 1:

I had the same problem. Add these browser options. From here: http://stockrt.github.io/p/emulating-a-browser-in-python-with-mechanize/

# Browser options
 br.set_handle_equiv(True)
 br.set_handle_gzip(True)
 br.set_handle_redirect(True)
 br.set_handle_referer(True)
 br.set_handle_robots(False)

 # Follows refresh 0 but not hangs on refresh > 0
 br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

I also recommend using debug messages

# Want debugging messages?#br.set_debug_http(True)#br.set_debug_redirects(True)#br.set_debug_responses(True)

Post a Comment for "Set Mechanize To Accept Cookies"