def get_wyr_form2(request): if not request: return url, data = request.get_full_url(), request.get_data() forms, response = get_forms(url, data) soup = BeautifulSoup(response) if len(forms) < 1: if has_message(soup, "is shared by more than one"): raise ZipShared elif has_message(soup, "not correct for the selected State"): raise ZipIncorrect elif has_message(soup, "was not found in our database."): raise ZipNotFound elif has_message(soup, "Use your web browser's <b>BACK</b> capability "): raise WyrError else: raise NoForm else: challenge = get_challenge(soup) if challenge: form = forms[0] try: solution = captchasolver.solve(challenge) except Exception, detail: print >> sys.stderr, 'Exception in CaptchaSolve', detail print 'Could not solve:"%s"' % challenge, else: form.f['HIP_response'] = str(solution) request = form.click() form = get_wyr_form2(request) return form else:
def fill_form(f): ''' f is a form ''' if DEBUG: print "in fill_form, filling name" f.fill_name(i.prefix, i.fname, i.lname) if DEBUG: print "in fill_form, filling addr" f.fill_address(i.addr1, i.addr2) if DEBUG: print "in fill_form, filling phone" f.fill_phone(i.phone) if DEBUG: print "in fill_form, filling textarea" textareacontrol = f.fill(type='textarea', value=i.full_msg) if DEBUG: print 'filled textareacontrol' , textareacontrol if DEBUG: print "in fill_form, filling all" if DEBUG: print "Printing all controls" for c in f.controls: if DEBUG: print "control: ", c.name, " type: ", c.type f.fill_all(city=i.city, zipcode=i.zip5, zip4=i.zip4, state=i.state.upper(), email=i.email, issue=['TECH', 'GEN', 'OTH'], subject=i.subject, reply='yes', Re='issue', #for billnelson newsletter='noAction', aff1='Unsubscribe', MessageType="Express an opinion or share your views with me") # page has one required control that has no name. so we need to fill it in #if DEBUG: # if (i.dist == 'SD-00' or 'coburn' in b.url): # empty_controls = [c for c in f.controls if not c.value] # for c in empty_controls: # print f.fill('OTH', control=c) # Solve captchas. I included this here because it was placed here by Aaron, # but I haven't found a captcha that it works on. -NKF challenge = get_challenge() if challenge: print "Found challenge!" try: solution = captchasolver.solve(challenge) except Exception, detail: print >> sys.stderr, 'Exception in CaptchaSolve', detail print >> sys.stderr, 'Could not solve:"%s"' % challenge,