2017-04-10 9 views
0

요청 모듈을 사용하여 웹 봇을 만들고 있습니다. 나는 그것에 recaptcha가있는 양식을 통과해야합니다. 나는이 recaptcha에 대한 g-captcha-response를 생성 할 수있는 지역 웹 사이트를 가지고 있습니다. 나는 g-captcha-response가 recaptcha를 통과하기 위해 필요한 유일한 후 매개 변수인지 알고 싶었습니다. 그렇지 않은 경우 어떤 다른 정보를 게시해야합니까?파이썬 요청으로 Google Recaptcha 처리하기

CaptchaKey = # g-captcha-response from my local website 

Session = requests.Session() 
FormData = { 
    'g-captcha-response': CaptchaKey 
} 
Session.post(SubmitURL, data=FormData) 

답변

0

reCaptcha documentation 여기에 꽤 좋은 조종을 제공합니다

여기 내 코드입니다. 파이썬과 요청을 통해 가장 기본적인면에서 다음과 같은 것을 보게 될 것입니다.

import requests, json 

try: 
    content = requests.post(
     'https://www.google.com/recaptcha/api/siteverify', 
     data={ 
      'secret': RECAPTCHA_SECRET, 
      'response': captcha_response_from_form, 
      'remoteip': USER_IP_ADDRESS, 
     } 
    ).content 
except ConnectionError: # Handle fundamental connectivity issues 
    # Handle your error state 

# Will throw ValueError if we can't parse Google's response 
content = json.loads(content) 

if not 'success' in content or not content['success']: 
    # The reCaptcha hasn't passed...