def _solve_google_captcha(self, resp):
# set up the captcha page markup for parsing
tree = fromstring(resp.text)
# extract and request the captcha image
resp = self.request('https://ipv4.google.com' + tree.xpath('//img/@src')[0], redirect=False, cookiejar=self.cookiejar, agent=self.user_agent)
# store the captcha image to the file system
with tempfile.NamedTemporaryFile(suffix='.jpg') as fp:
fp.write(resp.raw)
fp.flush()
# open the captcha image for viewing in gui environments
w = webbrowser.get()
w.open('file://' + fp.name)
self.alert(fp.name)
_payload = {'captcha':raw_input('[CAPTCHA] Answer: ')}
# temporary captcha file removed on close
# extract the form elements for the capctah answer request
form = tree.xpath('//form[@action="CaptchaRedirect"]')[0]
for x in ['continue', 'id', 'submit']:
_payload[x] = form.xpath('//input[@name="%s"]/@value' % (x))[0]
# send the captcha answer
return self.request('https://ipv4.google.com/sorry/CaptchaRedirect', payload=_payload, cookiejar=self.cookiejar, agent=self.user_agent)
评论列表
文章目录