Integrating selenium with 2captcha to solve Recapv2 - python-3.x

I'm trying to make a script that autofills info for a specific form, I created that and it autofills fine but when I the script clicks on the enter button a captcha pops up, I decided to take the 2captcha route rather then the audio captcha bypass. I found a package that simplifies the 2cap API down for you(https://pypi.org/project/2captcha-python/#recaptcha-v2). I can send a request to 2captcha and they solve the captcha, I know this because my daily stats go up 1 everytime I run the script, but nothing happens on the selenium browser. Any reason?
current code is
solver = TwoCaptcha('MYAPIKEY')
config = {
'apiKey': 'MYAPIKEY',
'softId': 123,
'callback': 'https://your.site/result-receiver',
'defaultTimeout': 120,
'recaptchaTimeout': 600,
'pollingInterval': 10,
}
solver = TwoCaptcha(**config)
result = solver.recaptcha(sitekey='6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
url="https://mailchi.mp/2d4364715d21/b66a2p7spo",)
I run this inside of a try: except: with the autofill code in it after It clicks enter(when the captcha pops up) any one have any ideas on how I can solve this? I've been trying for a couple hours and I can't figure it out.
Note: I left softId and callback as the default values because I don't have a softId from 2cap and I don't have a website either, if that's the issue please advise on how I can go about solving it.
Thanks in advance!

Related

Integrate GeeTestTask(python3_anticaptcha) with selenium in python3

I have a problem about python3_anticaptcha (api provided by anti-captcha.com), search on web, find support and try over a month but no luck.
API doc:
https://anticaptcha.atlassian.net/wiki/spaces/API/pages/416972814/GeeTestTaskProxyless+-+captcha+from+geetest.com+without+proxy
I am doing a auto login on a website, and copy the api on anti-captcha's doc:
def runGee(self, challenge):
print("start gee")
try:
# Enter the key to the AntiCaptcha service from your account. Anticaptcha service key.
ANTICAPTCHA_KEY = "mycode"
# обязательные параметры
websiteURL = "https:\/\/www.nike.com.hk"
gt = "2328764cdf162e8e60cc0b04383fef81"
print("sloving1")
print("challenge:" ,challenge)
# пример работы с GeeTestTask без прокси
result = GeeTestTaskProxyless.GeeTestTaskProxyless(anticaptcha_key=ANTICAPTCHA_KEY,
websiteURL=websiteURL,
gt=gt).captcha_handler(challenge=challenge)
print("sloving2")
print(result)
print("--end gee--")
except Exception as err:
print(err)
print("--end with error--")
However, the geetask start over 3 minute(or more), and got error everytime. usually error code like:
{'errorId': 34, 'errorCode': 'ERROR_TOKEN_EXPIRED', 'errorDescription': 'Captcha provider
reported that additional variable token has expired.', 'taskId': 1204556667}
or
{'errorId': 12, 'errorCode': 'ERROR_CAPTCHA_UNSOLVABLE', 'errorDescription': ' Captcha
could not be solved by 5 different workers.', 'taskId': 1204060350}
..etc
depends on what parameter i passed.
May i know am i passing the right value to geetask? or some wrong on the code?
Moreover, if geetest return the correct value, i need to do any else to pass capcha(or pass code to geetest server) or GeeTestTaskProxyless already done(not to do anything)?
it is extremely hard to me, does anyone had used this api successfully? Thanks
The problem is not in the anticaptcha but in the geetest provider.
The token challenger can only be used once, when your browser loads the geetest captcha it expires the token.
To fix this problem, you only need to block the request that consumes the token in your browser.
go to devtools and add the block for the geestest captcha API in the browser, like this:
You can automatically integrate this into the selenium with the following command:
driver.execute_cdp_cmd('Network.setBlockedURLs', {"urls": ["api.geetest.com/get.php"]})
driver.execute_cdp_cmd('Network.enable', {})
It seems for me that those errors are because of proxy (if you use any) or just bad IP.
Personally, I use another captcha service and I didn't have such problems with it.
I advice you to try it, it's actually much easier: https://2captcha.com/2captcha-api#solving_geetest
You should send a request like this one:
https://2captcha.com/in.php?key=1abc234de56fab7c89012d34e56fa7b8&method=geetest&gt=f1ab2cdefa3456789012345b6c78d90e&challenge=12345678abc90123d45678ef90123a456b&api_server=api-na.geetest.com&pageurl=https://www.example.com/page/
What you need to archieve is to get correct answer from it, like this one:
{
"challenge":"1a2b3456cd67890e12345fab678901c2de",
"validate":"09fe8d7c6ba54f32e1dcb0a9fedc8765",
"seccode":"12fe3d4c56789ba01f2e345d6789c012|jordan" }
Then you just need to implement that answer on a site. Just read the first link I gave you.
Cheers.

Scrape Humble Bundle games using "Requests" module

I'm actually trying get the information of the games contained in this webpage: https://www.humblebundle.com/store/search?sort=discount&filter=onsale
The first thing I tried was to replicate what one user did to help me on a similar problem days ago, doing a POST request to access directly where the data I need from the web comes from. Here's the link of that question in case you still don't know what I'm trying to achieve.
To do that, I first executed this code to get the HTML file of the web without the elements loaded:
import requests
req = requests.get("https://www.humblebundle.com/store/search?sort=discount&filter=onsale")
a = open("humble.txt", "w")
a.write(req.text)
a.close()
It returned me this code.
You can notice in the 1084 line a script called "storefront-constants-json-data", It called my attention because It was the unique that had some variables related to the page. Then I thought, "Hey, there must be more information about this script somewhere". The I clicked "Inspect element" on the web and went to the "Network" tab. I searched that script name in every JS file and found just one reference, this one.
At this point I'm lost, In fact, I don't even know If I'm in the right way (because I don't know any JavaScript). Can someone show me the path to get those Humble Bundle games :s ?.
Pd: I wrote a similar question yesterday but It was very vague, so I decided to rewrite It giving all the information I have and explaining what I've tried.
Pd2: I'd prefer not to do It with Selenium or similar modules, they are too slow.
The data you see on the webpage is loaded through AJAX requests from different URL. If you open Network Inspector, you can see the URL of the requests - and the data are returned in Json format:
import requests
data = requests.get('https://www.humblebundle.com/store/api/search?sort=discount&filter=onsale&request=1').json()
from pprint import pprint
pprint(data)
Prints:
{'num_pages': 245,
'num_results': 4894,
'page_index': 0,
'request': 1,
'results': [{'content_types': ['game'],
'cta_badge': None,
'current_price': [0.0, 'EUR'],
'delivery_methods': ['download'],
'empty_tpkds': {},
'featured_image_recommendation': 'https://hb.imgix.net/2e18a2a9316c0136abf25670bf67ed389c855e4f.jpeg?auto=compress,format&fit=crop&h=154&w=270&s=64e2f8ad8654541c0620d8e018fa2025',
'full_price': [0.01, 'EUR'],
'human_name': 'Crying Suns Demo',
'human_url': 'crying-suns-demo',
'icon': 'https://hb.imgix.net/2e18a2a9316c0136abf25670bf67ed389c855e4f.jpeg?auto=format&fit=crop&h=64&w=103&s=dcf803da86b9bcf4cd2c0d038ddf16fb',
'icon_dict': {'download': {'available': ['windows', 'mac'],
'unavailable': ['linux']}},
'large_capsule': 'https://hb.imgix.net/2e18a2a9316c0136abf25670bf67ed389c855e4f.jpeg?auto=compress,format&fit=crop&h=353&w=616&s=d50b680a5bfd2c6c6acdb4c745db8428',
'machine_name': 'cryingsuns_demo_storefront',
'non_rewards_charity_split': 0.0,
'platforms': ['windows', 'mac'],
'rating_for_current_region': 'pegi',
'rewards_split': 0.1,
'sale_end': 32503708740.0,
'sale_type': 'normal',
'standard_carousel_image': 'https://hb.imgix.net/2e18a2a9316c0136abf25670bf67ed389c855e4f.jpeg?auto=compress,format&fit=crop&h=206&w=360&s=015688fbe32c7e3e185bdcaddc72e02a',
'type': 'product',
'xray_traits_thumbnail': 'https://hb.imgix.net/2e18a2a9316c0136abf25670bf67ed389c855e4f.jpeg?auto=compress,format&fit=crop&h=84&w=135&s=eefaf495f9379b213672d82ddeae672a'},
...and so on.
The screenshot from network inspector:

webdriver-sync running asynchronously?

I'm trying to create selenium tests that run each step synchronously, without using .then(), or async/await. The reason for this is that I want to create a set of functions that allow pretty much anyone on our test team, almost regardless of tech skills to write easy to read automated tests. It looks to me like webdriver-sync should give me exactly what I want. However, the following dummy code is producing problems:
var wd = require('webdriver-sync');
var By = wd.By;
var Chromedriver = wd.Chromedriver;
var driver = new Chromedriver;
driver.get('https://my.test.url');
var myButton = driver.findElement(By.cssSelector('[id*=CLICK_ME]'));
myButton.click();
It tries to run - browser is launched, and page starts to load... but the steps are not executed synchronously - it goes on and tries to find and click "myButton" before the page has finished loading, throwing a "no such element" error... which to me kinda defeats the point of webdriver-sync?! Can someone tell me where I am going wrong?
FWIW, I have webdriver-sync 1.0.0, node v7.10.0, java 1.8.0_74, all running on CentOS 7.
Thanks in advance!
You need to put double-quotes around "CLICK_ME" as it's a string value.
Generally, though, it's a good idea to Wait for specific elements because dynamic pages are often "ready" before all their elements have been created.

AutoIt v3: _IENavigate + _IELoadWait Not Working as Expected?

This code is supposed to open a new browser set at "www.website.com," submit a username and password, wait for the page to load after being submitted, navigate to a new page, and inject a javascript code into the address bar.
My current results from this code are opening a new browser set at "www.website.com," submit a username and password. The submit works, then from here, the code breaks and instead of navigating to the next page (page2) it just hangs.
Even when I add an ignore command to the _IEFormSubmit($oForm) I can't get my page to navigate to the next page.
#include <IE.au3>
#RequireAdmin
Local $oIE = _IECreate("http://www.website.com")
;_IELinkClickByText($oIE, "Sign In") ;Optional
Local $oForm = _IEFormGetObjByName($oIE, "regular-user-login-form")
Local $oText = _IEFormElementGetObjByName($oForm, "log")
_IEFormElementSetValue($oText, "username")
Local $oText = _IEFormElementGetObjByName($oForm, "pwd")
_IEFormElementSetValue($oText, "password")
_IEFormSubmit($oForm)
_IENavigate($oIE, "http://www.website.com/page2/")
Send("{F4}javascript:check_in();{ENTER}")
Please for the love of god, what am I doing wrong.
Edit: I've also changed the _IEFormSubmit($oForm) to another javascript submit and I can still log in without any problems, but once I reach that next page I can't use _IENavigate, so the problem has to lie there.
I have automated so many different pages and sometimes the script gets stuck on _IEFormSubmit for no reason. That's an AutoIt bug.
Her's a quick fix for that
_IEFormSubmit($oForm, 0)
_IELoadWait($oIE, 1000)
Your code should be:
#include <IE.au3>
#RequireAdmin
Local $oIE = _IECreate("http://www.website.com")
;_IELinkClickByText($oIE, "Sign In") ;Optional
Local $oForm = _IEFormGetObjByName($oIE, "regular-user-login-form")
Local $oText = _IEFormElementGetObjByName($oForm, "log")
_IEFormElementSetValue($oText, "username")
Local $oText = _IEFormElementGetObjByName($oForm, "pwd")
_IEFormElementSetValue($oText, "password")
_IEFormSubmit($oForm, 0)
_IELoadWait($oIE, 1000)
_IENavigate($oIE, "http://www.website.com/page2/")
Send("{F4}javascript:check_in();{ENTER}")
Onetime, I tried to report two bugs to autoit forum, but the guys who are there are pretty frustrated fellas. So, now when I find one, I just solve it my way.
Off topic:
When dealing with objects you should know of another bug
If $oInput.outertext = "Continue" then ...
The above code will sometime fail even if the outertext matches.
This is solved using, use
If $oInput.outertext == "Continue" then ...

Guide.ShowSignIn(1, false) Value not in range exception

In a new Xna game I wroted this:
GamerServicesComponent gsc = new GamerServicesComponent(this);
gsc.Initialize();
Components.Add(gsc);
if(!GamerServicesDispatcher.IsInitialized)
GamerServicesDispatcher.Initialize(Services);
And in the Update method
if (Keyboard.GetState().IsKeyDown(Keys.S))
if (!Guide.IsVisible)
Guide.ShowSignIn(1, false); // true doesn't solve it nor 2 or 4 as paneCount
I'm receiving a
Value does not fall within the expected range.
Anybody?
It seems that Guide.ShowSignIn() can't be used anymore. I Don't know the reason nor if it is really true. But I couldn't get it working with ShowSignIn.
The way I had to login was by pressing the Home button.
The Guide will appear and you can simply follow the Guide to login.
Waiting a few frames before calling Guide.ShowSignIn() works for me. I don't call it until my game has loaded all assets and at least I frame has been rendered.

Resources