Hey guys,
I'm working on some shop wiz search functions using Mechanize but am running into some problems.
import re import mechanize import cookielib import time from mechanize import ParseResponse br = mechanize.Browser() br.set_handle_robots(False) br.set_handle_equiv(True) br.set_handle_redirect(True) br.set_handle_referer(True) cj = cookielib.LWPCookieJar() br.set_cookiejar(cj) br.set_proxies({"https": "207.188.135.38:38328"}) br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:37.0) Gecko/20100101 Firefox/37.0')] br.open("http://www.neopets.com/market.phtml?type=wizard") br.select_form(name="login") # Browser passes through unknown attributes (including methods) # to the selected HTMLForm. br["username"] = REDACTED # (the method here is __setitem__) br["password"] = REDACTED # Submit current form. Browser calls .close() on the current response on # navigation, so this closes response1 after_login = br.submit() print br.title() print after_login.geturl() # print currently selected form (don't call .submit() on this, use br.submit()) f = open('after_login.html', 'w') f.write(after_login.read()) f.close() #for form in br.forms(): # print form br.select_form(nr=1) #br["type"] = "process_wizard" #br["feedset"] = "0" br["shopwizard"] = "cheese" br["table"] = ["shop",] br["criteria"] = ["containing",] br["min_price"] = "0" br["max_price"] = "99999" time.sleep(5); after_search = br.submit() print br.title() print after_search.geturl() #print after_search.read() f = open('after_search.html', 'w') f.write(after_search.read()) f.close()
Opening after_search.html provides the error Error: You have been directed to this page from the wrong place! If you KEEP getting this error, chances are you have some security settings enabled that are not letting you play Neopets correctly.
Click here to see some tips that might help you fix this problem."
Can someone please explain what I'm doing wrong and how to fix it? Thanks
Also, I look at the packets sent using mechanize and Firefox and they both apear to send the same form data.
Edited by Poooppe, 18 May 2015 - 06:40 PM.