Skip to content

Commit 462659e

Browse files
authored
Follow-up package refresh (#99)
* Fix Mixin class * fix deprecated test * bump setup-python version * add support new version of python * add classifiers for python version * revert cache for setup-python * remove fields from docs * Fix return in CookieMixin * Make dry task in data * fix call super.__init__ * update README * switch selenium tests to use chrome * refresh funcaptcha example * fix ImageToTextTask class hierarchy * migrate to nose2 * set timeout in gha * fix multiprocessing for nose2
1 parent 34e3f89 commit 462659e

11 files changed

Lines changed: 123 additions & 108 deletions

File tree

.github/workflows/e2e.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
jobs:
1010
test:
1111
runs-on: ubuntu-latest
12+
timeout-minutes: 30
1213
steps:
1314
- uses: actions/checkout@v1
1415

@@ -20,8 +21,7 @@ jobs:
2021
- name: Build distribution
2122
run: make install
2223

23-
- name: Install Geckodriver
24-
run: make gecko
24+
- uses: nanasess/setup-chromedriver@v1
2525

2626
- name: Run integration tests
2727
run: make test

.github/workflows/pythonpackage.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@ jobs:
1010
max-parallel: 4
1111
fail-fast: false
1212
matrix:
13-
python-version: [2.7, 3.5, 3.6, 3.7]
13+
python-version:
14+
- '2.7'
15+
- '3.5'
16+
- '3.6'
17+
- '3.7'
18+
- '3.8'
19+
- '3.9'
20+
- '3.10'
1421

1522
steps:
1623
- uses: actions/checkout@v1
1724

1825
- name: Set up Python ${{ matrix.python-version }}
19-
uses: actions/setup-python@v1
26+
uses: actions/setup-python@v3
2027
with:
2128
python-version: ${{ matrix.python-version }}
2229

Makefile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
.PHONY: lint fmt build docs install test
1+
CHROMEDRIVER_VERSION=99.0.4844.17
2+
CHROMEDRIVER_DIR=${PWD}/geckodriver
3+
4+
.PHONY: lint fmt build docs install test gecko
25

36
build:
47
python setup.py sdist bdist_wheel
@@ -16,14 +19,13 @@ install_pkg:
1619
pip install .
1720

1821
gecko:
19-
wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz
20-
mkdir geckodriver
21-
tar -xzf geckodriver-v0.24.0-linux64.tar.gz -C geckodriver
22-
rm geckodriver-v0.24.0-linux64.tar.gz
22+
mkdir -p ${CHROMEDRIVER_DIR}
23+
wget -q -P ${CHROMEDRIVER_DIR} "http://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip"
24+
unzip ${CHROMEDRIVER_DIR}/chromedriver* -d ${CHROMEDRIVER_DIR}
25+
rm ${CHROMEDRIVER_DIR}/chromedriver_linux64.zip
2326

2427
test:
25-
# nosetests tests -v --with-coverage --cover-package=python_anticaptcha --processes=8
26-
PATH=$$PATH:$$PWD/geckodriver nosetests tests --verbosity=3 --processes=8 --process-timeout=1800
28+
PATH=$$PWD/geckodriver:$$PATH nose2 --verbose
2729

2830
clean:
2931
rm -r build geckodriver

README.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,6 @@ Example snippet for reporting an incorrect image task:
151151
print job.get_captcha_text()
152152
job.report_incorrect()
153153
154-
Custom tasks
155-
############
156-
157-
There is support for your own (captcha) forms. It allows you to analyze any data in various ways, eg. classify offensive
158-
image, count elements on the image, etc. The scope of the data, the form to describe them, you specify yourself.
159-
160-
For details, go to 'Custom fields' section in the documentation.
161-
162154
Setup proxy
163155
###########
164156

@@ -203,8 +195,6 @@ In the event of an application error, the AnticaptchaException exception is thro
203195
else:
204196
raise
205197
206-
207-
208198
.. usage-end
209199
210200
Versioning

docs/api.rst

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,4 @@ Tasks
2020

2121
.. automodule:: python_anticaptcha.tasks
2222
:members:
23-
:undoc-members:
24-
25-
.. _form_fields:
26-
27-
Fields
28-
------
29-
30-
.. automodule:: python_anticaptcha.fields
31-
:members:
32-
:undoc-members:
23+
:undoc-members:

examples/funcaptcha_request.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
import requests
33
from os import environ
44
import re
5-
from random import choice
65

76
from python_anticaptcha import AnticaptchaClient, FunCaptchaTask
87

98
api_key = environ["KEY"]
109
site_key_pattern = 'public_key: "(.+?)",'
10+
site_key_pattern = 'public_key: "(.+?)",'
11+
surl_pattern = 'surl: "(.+?)",'
1112
url = "https://client-demo.arkoselabs.com/solo-animals"
1213
client = AnticaptchaClient(api_key)
1314
session = requests.Session()
@@ -37,23 +38,31 @@ def get_form_html():
3738

3839
def get_token(form_html):
3940
proxy = parse_url(proxy_url)
40-
4141
site_key = re.search(site_key_pattern, form_html).group(1)
42-
task = FunCaptchaTask(url, site_key, user_agent=UA, **proxy)
42+
print("Determined site-key:", site_key)
43+
surl = re.search(surl_pattern, form_html).group(1)
44+
print("Determined surl:", surl)
45+
task = FunCaptchaTask(surl, site_key, user_agent=UA, **proxy)
4346
job = client.createTask(task)
44-
job.join(maximum_time=10 ** 4)
47+
job.join(maximum_time=10**4)
4548
return job.get_token_response()
4649

4750

4851
def form_submit(token):
4952
return requests.post(
50-
url="{}/verify".format(url), data={"name": "xx", "fc-token": token}
53+
url="{}/verify".format(url),
54+
data={"name": "xx", "fc-token": token},
55+
proxies={
56+
"http": proxy_url,
57+
"https": proxy_url,
58+
},
5159
).text
5260

5361

5462
def process():
5563
html = get_form_html()
5664
token = get_token(html)
65+
print("Received token:", token)
5766
return form_submit(token)
5867

5968

examples/recaptcha_selenium.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def get_sitekey(driver):
4646

4747

4848
if __name__ == "__main__":
49-
from selenium.webdriver import Firefox
50-
from selenium.webdriver.firefox.options import Options
49+
from selenium.webdriver import Chrome
50+
from selenium.webdriver.chrome.options import Options
5151

5252
options = Options()
53-
# options.add_argument('-headless')
54-
driver = Firefox(firefox_options=options)
53+
options.add_experimental_option('prefs', {'intl.accept_languages': 'en_US'})
54+
driver = Chrome(options=options)
5555
assert EXPECTED_RESULT in process(driver)

0 commit comments

Comments
 (0)