def _solve_google_captcha(self, resp):
# set up the captcha page markup for parsing
tree = fromstring(resp.text)
# extract and request the captcha image
#captchaUrl = 'https://ipv4.google.com' + tree.xpath('//img/@src')[0]
#print(captchaUrl)
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 open('/tmp/111.jpg','w') as fp:
fp.write(resp.raw)
fp.flush()
print(fp.name)
# 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="index"]')[0]
for x in ['q', 'continue', '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)
评论列表
文章目录