Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add captcha.guru service #8

Merged
merged 5 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add an example of solving FunCaptcha
  • Loading branch information
sergey-scat committed Oct 7, 2022
commit 7181f3c67763e01f026b7c691a7e28696e1a2852
77 changes: 77 additions & 0 deletions examples/async_funcaptcha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""
FunCaptcha solving example
"""

import asyncio
import os
import re

import httpx
from lxml import html # type: ignore
from unicaps import AsyncCaptchaSolver, CaptchaSolvingService, exceptions # type: ignore

URL = 'https://client-demo.arkoselabs.com/solo-animals'
URL_VERIFY = 'https://client-demo.arkoselabs.com/solo-animals/verify'
API_KEY = os.getenv('API_KEY_2CAPTCHA', default='<PLACE_YOUR_API_KEY_HERE>')


async def main():
""" Init AsyncCaptchaSolver and run the example """
async with AsyncCaptchaSolver(CaptchaSolvingService.TWOCAPTCHA, API_KEY) as solver:
await run(solver)


async def run(solver):
""" Load and solve FunCaptcha """

# create an HTTP2 session
async with httpx.AsyncClient(http2=True) as session:
# open page and extract CAPTCHA URL
response = await session.get(URL)
page = html.document_fromstring(response.text)

# extract Public Key and Service URL values
script = page.xpath('//script[contains(text(), "public_key")]')[0].text
regexp = re.search(
r'public_key: ?"([0-9A-Z-]+)",\s*surl: ?"(.*)",',
script
)
public_key = regexp.group(1)
service_url = regexp.group(2)

# solve FunCaptcha
try:
solved = await solver.solve_funcaptcha(
public_key=public_key,
page_url=URL,
service_url=service_url
)
except exceptions.UnicapsException as exc:
print(f'FunCaptcha solving exception: {str(exc)}')
return False, None

# post solved captcha token
response = await session.post(
URL_VERIFY,
data={
'name': 'test',
'verification-token': solved.solution.token,
'fc-token': solved.solution.token
}
)

# check the result
if '<h3>Solved!</h3>' in response.text:
print('The FunCaptcha has been solved correctly!')
# report good CAPTCHA
await solved.report_good()
return True, solved

print('The FunCaptcha has not been solved correctly!')
# report bad CAPTCHA
await solved.report_bad()
return False, solved


if __name__ == '__main__':
asyncio.run(main())
70 changes: 70 additions & 0 deletions examples/funcaptcha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
FunCaptcha solving example
"""
import os
import re

import httpx
from lxml import html # type: ignore
from unicaps import CaptchaSolver, CaptchaSolvingService, exceptions # type: ignore

URL = 'https://client-demo.arkoselabs.com/solo-animals'
URL_VERIFY = 'https://client-demo.arkoselabs.com/solo-animals/verify'
API_KEY = os.getenv('API_KEY_2CAPTCHA', default='<PLACE_YOUR_API_KEY_HERE>')


def run(solver):
""" Load and solve FunCaptcha """

# create an HTTP2 session
with httpx.Client(http2=True) as session:
# open page and extract CAPTCHA URL
response = session.get(URL)
page = html.document_fromstring(response.text)

# extract Public Key and Service URL values
script = page.xpath('//script[contains(text(), "public_key")]')[0].text
regexp = re.search(
r'public_key: ?"([0-9A-Z-]+)",\s*surl: ?"(.*)",',
script
)
public_key = regexp.group(1)
service_url = regexp.group(2)

# solve FunCaptcha
try:
solved = solver.solve_funcaptcha(
public_key=public_key,
page_url=URL,
service_url=service_url
)
except exceptions.UnicapsException as exc:
print(f'FunCaptcha solving exception: {str(exc)}')
return False, None

# post solved captcha token
response = session.post(
URL_VERIFY,
data={
'name': 'test',
'verification-token': solved.solution.token,
'fc-token': solved.solution.token
}
)

# check the result
if '<h3>Solved!</h3>' in response.text:
print('The FunCaptcha has been solved correctly!')
# report good CAPTCHA
solved.report_good()
return True, solved

print('The FunCaptcha has not been solved correctly!')
# report bad CAPTCHA
solved.report_bad()
return False, solved


if __name__ == '__main__':
with CaptchaSolver(CaptchaSolvingService.TWOCAPTCHA, API_KEY) as captcha_solver:
run(captcha_solver)
3 changes: 2 additions & 1 deletion examples/run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
'geetest',
'geetest_v4',
'capy_puzzle',
'text'
'text',
'funcaptcha'
]

logging.basicConfig(level=logging.DEBUG)
Expand Down