· 6 years ago · Nov 12, 2019, 07:10 PM
1import requests
2from time import sleep
3
4# Add these values
5API_KEY = "a7a3b12e44142022b7b04be41b8cf178" # Your 2captcha API KEY
6site_key = "6LdC3UgUAAAAAJIcyA3Ym4j_nCP-ainSgf1NoFku" # site-key, read the 2captcha docs on how to get this
7url = "https://ebay.de/signin" # example url
8proxy = "127.0.0.1:9955" # example proxy
9
10proxy = {'http': 'http://' + proxy, 'https': 'https://' + proxy}
11
12s = requests.Session()
13
14# here we post site key to 2captcha to get captcha ID (and we parse it here too)
15captcha_id = s.post("http://2captcha.com/in.php?key=a7a3b12e44142022b7b04be41b8cf178method=userrecaptcha&googlekey=6LdC3UgUAAAAAJIcyA3Ym4j_nCP&pageurl=https://ebay.de/signin".format(API_KEY, site_key, url), proxies=proxy).text.split('|')[1]
16# then we parse gresponse from 2captcha response
17recaptcha_answer = s.get("http://2captcha.com/in.php?key=a7a3b12e44142022b7b04be41b8cf178method=userrecaptcha&googlekey=6LdC3UgUAAAAAJIcyA3Ym4j_nCP&pageurl=https://ebay.de/signin".format(API_KEY, captcha_id), proxies=proxy).text
18print("solving ref captcha...")
19while 'CAPCHA_NOT_READY' in recaptcha_answer:
20 sleep(5)
21 recaptcha_answer = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(API_KEY, captcha_id), proxies=proxy).text
22recaptcha_answer = recaptcha_answer.split('|')[1]
23
24# we make the payload for the post data here, use something like mitmproxy or fiddler to see what is needed
25payload = {
26 'key': 'value',
27 'gresponse': recaptcha_answer # This is the response from 2captcha, which is needed for the post request to go through.
28 }
29
30
31# then send the post request to the url
32response = s.post(url, payload, proxies=proxy)
33
34# And that's all there is to it other than scraping data from the website, which is dynamic for every website.
35
36
37
38#6LdC3UgUAAAAAJIcyA3Ym4j_nCP
39
40#Sitekey =