2

I'm trying to write a script so I can log into a website, but in order to do that I need to present the captcha. The only way to get that direct image of the captcha from the URL is to extract the giant string name 'challenge' but I have not been able to do it with BeautifulSoup for some reason. What is the best way to extract the long string?

var RecaptchaState = {
    site : '4LfjPgEA56AABAJExraAeYXdMbVhPcG__Hyv-URXF',
    challenge : '03AHJ_VusE_PgNB0vfBpD2h53o8uGMt1MeKi9bzhOTsjt0ze7SKmHVNe8uADceoU3JLPjpp8cJCVDGiYKo1ho-r1JcV19tm26doUHqevixJjH8SZ26i4EWbUOQLEuODf0Kt6JI0ZhtfiIaIXDg9MhUyDCEt_qxFWbSHA',
    is_incorrect : false,
    programming_error : '',
    error_message : '',
    server : 'http://www.google.com/recaptcha/api/',
    timeout : 18000
};

document.write('
<scr>
 ');
</scr>
FlowofSoul
  • 510
  • 7
  • 17

2 Answers2

0

BeautifulSoup does not parse js, you need to dothis with a regex or similar.

knutin
  • 5,033
  • 19
  • 26
0

I'd just use a regular expression. Not sure about this, but I don't think beautifulsoup parses javascript--only (x)html:

challenge = re.search(r"challenge *: *'(\S+)'", x).group(1)

Gives:

'03AHJ_VusE_PgNB0vfBpD2h53o8uGMt1MeKi9bzhOTsjt0ze7SKmHVNe8uADceoU3JLPjpp8cJCVDGiYKo1ho-r1JcV19tm26doUHqevixJjH8SZ26i4EWbUOQLEuODf0Kt6JI0ZhtfiIaIXDg9MhUyDCEt_qxFWbSHA'

twneale
  • 2,836
  • 4
  • 29
  • 34