Skip to content

Commit

Permalink
Merge pull request #36 from ad-m/funcaptcha-example
Browse files Browse the repository at this point in the history
Update Funcaptcha example
  • Loading branch information
ad-m committed Jun 28, 2019
2 parents 4fe5a25 + 9f069cf commit a342d51
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions examples/funcaptcha.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from urllib.parse import urlparse

import requests
from os import environ
import re
from random import choice

from python_anticaptcha import AnticaptchaClient, FunCaptchaTask, Proxy
from python_anticaptcha import AnticaptchaClient, FunCaptchaTask

api_key = environ['KEY']
site_key_pattern = 'data-pkey="(.+?)"'
Expand All @@ -17,13 +19,24 @@
proxy_urls = environ['PROXY_URL'].split(',')


def parse_url(url):
parsed = urlparse(url)
return dict(
proxy_type=parsed.scheme,
proxy_address=parsed.hostname,
proxy_port=parsed.port,
proxy_login=parsed.username,
proxy_password=parsed.password
)


def get_form_html():
return session.get(url).text


def get_token(form_html):
proxy_url = choice(proxy_urls)
proxy = Proxy.parse_url(proxy_url)
proxy = parse_url(proxy_url)

site_key = re.search(site_key_pattern, form_html).group(1)
task = FunCaptchaTask(url, site_key, proxy=proxy, user_agent=UA)
Expand Down

0 comments on commit a342d51

Please sign in to comment.