This should work for you. Obviously, you will need to update the predicate method. Also, do you have ongoing sex information? id, class, label, etc.
import mechanize import re class MyBrowser: def __init__(self): self.user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)' self.cj = mechanize.LWPCookieJar() self.setup_browser(enable_debug=False) def find_by_crazy_name(self, control): if re.match('^[\w]{32,}$', control.name): return True return False def runit(self): self.agent.open('http://localhost') self.agent.select_form(name="foo") field = self.agent.form.find_control(predicate=self.find_by_crazy_name) field._value = "POOP" response = self.agent.submit() def enable_debug(self): self.agent.set_debug_http(True) self.agent.set_debug_redirects(True) self.agent.set_debug_responses(True) def setup_browser(self, enable_debug=False): self.agent = mechanize.Browser() self.agent.set_handle_redirect(True) self.agent.set_cookiejar(self.cj) self.agent.set_handle_referer(True) self.agent.set_handle_refresh(True) self.agent.set_handle_equiv(True) self.agent.set_handle_robots(False) self.enable_debug() self.agent.addheaders = [('User-Agent', self.user_agent)] if __name__ == "__main__": browser = MyBrowser() browser.runit()
It just fills the entire potential POOP field. A field is a match if it is 32 alphanumeric characters (e.g. md5)
source share