代碼如下:
    from urllib.request import urlopen
    from urllib.parse import urlencode
    import tornado.httpserver
    import tornado.ioloop
    import tornado.web
    
    #獲取key: https://www.google.com/recaptcha/whyrecaptcha
    publickey = '填入你的 public key'
    privatekey = '填入你的 private key'
    
    class Application(tornado.web.Application):
        def __init__(self):
            handlers = [
                (r'/', IndexHandler)
            ]
            settings = dict(
                template_path="templates",
            )
            tornado.web.Application.__init__(self, handlers, **settings)
    
    class IndexHandler(tornado.web.RequestHandler):
        def get(self):
            self.render('index.html', publickey=publickey)
        def post(self):
            url = 'http://www.google.com/recaptcha/api/verify'
            #驗(yàn)證碼
            challenge = self.get_argument('recaptcha_challenge_field')
            #用戶輸入
            response = self.get_argument('recaptcha_response_field')
            data = {
                'privatekey': privatekey,
                'remoteip': self.request.remote_ip,
                'challenge': challenge,
                'response': response
            }
            res = urlopen(url, data=urlencode(data).encode())
            #獲取驗(yàn)證結(jié)果,這里直接將返回結(jié)果輸出到頁(yè)面            
新聞熱點(diǎn)
疑難解答
圖片精選