ARTICLE AD BOX
I’m writing a Selenium script to auto-fill a contact form, like this one, and yeah, obviously the main site is different — cornerstonesalina.com/elements/contact-form/, there’s a math captcha like "5 + 3" or "10 ÷ 2". I’m using regex to parse it and lambdas for the calculations.
def solve_math_captcha(captcha_text): match = re.search(r'(\d+)\s*([+-×÷/])\s(\d+)', captcha_text) if not match: return None num1, op, num2 = int(match.group(1)), match.group(2), int(match.group(3)) ops = {'+': lambda a,b: a+b, '-': lambda a,b: a-b, '×': lambda a,b: a*b, '*': lambda a,b: a*b} return ops.get(op, lambda a,b: a+b)(num1, num2)Sometimes it solves correctly (5+3=8 ok), but for division it fails! "10 ÷ 2" gives 12, the form doesn’t submit. Regex matches (print(match.group(2)) shows '÷'), but the result...
The full script works on +-, but on ÷/ it’s always addition. What the hell? How do I fix it? What am I missing?
