There are three verification methods for this website:
1. Need to solve akamai
2. Need to use tls request
3. Need to pass nucaptcha OCR verification
Now I have solved all of them and open sourced them. You can write config or write software according to the open source demo.
If you have any questions, you can send me a private message for help.
1. Need to solve akamai
2. Need to use tls request
3. Need to pass nucaptcha OCR verification
Now I have solved all of them and open sourced them. You can write config or write software according to the open source demo.
If you have any questions, you can send me a private message for help.
[ Hidden Content! ]
Code:
from math import fabs
from weakref import proxy
import requests
import json
import sys
import random
import string
import re
import urllib
# captcha api config on https://www.clearcaptcha.com
akamai_api="http://api.clearcaptcha.com/captcha/akamai_v2";
tls_api="http://api.clearcaptcha.com/captcha/tls";
nucaptcha_api="http://api.clearcaptcha.com/captcha/nucaptcha_web";
token = 'test' # need replace your clearcaptcha token
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
proxy="resi.proxiware.com:8080:user-test_pool-1_geo-us_session-test:tesepassword" # need replace your proxy
def tls_result(url,method,headers,body,user_agent,proxy, cookie="", redirect=True):
data = {
'token': token,
'method': method,
'url': url,
'headers': json.dumps(headers),
'body': body,
'user_agent': user_agent,
'proxy': proxy,
'cookie': cookie,
'allow_redirect': str(redirect).lower()
}
try:
response = requests.post(tls_api, data=data)
return response.json()
except requests.RequestException as e:
print(str(e))
sys.exit()
def akamai_result(abck, bm_sz, website, ua_ver="129.0.0.0"):
data = {
'token': token,
'abck': abck,
'bm_sz': bm_sz,
'website': website,
'ua_ver': ua_ver
}
try:
response = requests.post(akamai_api, data=data)
return response.json()
except requests.RequestException as e:
print(str(e))
sys.exit()
session = requests.Session()
headers={
'Connection': 'keep-alive',
'User-Agent': user_agent,
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate, br',
'Referer': 'https://www.staples.com/',
'Origin': 'https://www.staples.com',
'sec-ch-ua': '"Google Chrome";v="129", "Not=A?Brand";v="8", "Chromium";v="129"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-User': '?1',
'Upgrade-Insecure-Requests': '1',
}
response_data = tls_result("https://www.staples.com/idm/com/login", "GET", headers, "", user_agent, proxy, "");
response_html = response_data["data"]["result"]
cookies = response_data["data"]["cookie"]
cookie_str = ''.join(cookies)
abck_match = re.search(r"_abck=(.*?);", cookie_str)
bm_sz_match = re.search(r"bm_sz=(.*?);", cookie_str)
abck = abck_match.group(1) if abck_match else None
bm_sz = bm_sz_match.group(1) if bm_sz_match else None
response_data = akamai_result(abck, bm_sz, "https://www.staples.com/", "129.0.0.0");
sensor_data = response_data["data"]["sensor_data"];
ua = response_data["data"]["ua"];
print('get sensor_data successfully!')
headers["User-Agent"]=ua
headers["Content-Type"]="text/plain;charset=UTF-8"
post_data={
"sensor_data": sensor_data,
}
post_data=json.dumps(post_data)
response_data = tls_result("https://www.staples.com/yuOSu6xwmw/XurpvFFv/DW/JYr1hS3JfOStf3/ag8GYDNC/PRFlP/S5CBw8C", "POST", headers, post_data, user_agent, proxy, cookie_str);
response_html = response_data["data"]["result"]
cookies = response_data["data"]["cookie"]
if '{"success": true}' not in response_html:
print('akamai verification failed!')
sys.exit()
print('akamai verification successfully!')
cookie_str = ''.join(cookies)
headers["Content-Type"]="application/json"
post_data='{"userAgent":"'+ua+'","stplSessionId":"93ec842ae7ef1c6ee47b26591a23828b","placement":"Login","page":1,"requestUrl":"https://www.staples.com/idm/com/login","ndsModeValue":"","captchaAnswer":"","nuCaptchaToken":"","rememberMe":true,"username":"[email protected]","password":"123123123"}'
response_data = tls_result("https://www.staples.com/idm/api/identityProxy/logincommon", "POST", headers, post_data, user_agent, proxy, cookie_str);
response_html = response_data["data"]["result"]
if '"hasCaptchaResponseFl":true' in response_html:
item_json=json.loads(response_html)
captchaResponseHtml=item_json["body"]["captchaResponse"]["captchaResponseHtml"]
reMatch=re.search(r'"challengeBaseUrl":"(.*?)"', captchaResponseHtml)
challengeBaseUrl = reMatch.group(1) if reMatch else None
reMatch=re.search(r'"r":"(.*?)"', captchaResponseHtml)
requestId = reMatch.group(1) if reMatch else None
reMatch=re.search(r'"token":"(.*?)"', captchaResponseHtml)
requestToken = reMatch.group(1) if reMatch else None
reMatch=re.search(r'"shuffleSeed":(.*?),', captchaResponseHtml)
shuffleSeed = reMatch.group(1) if reMatch else None
reMatch=re.search(r'"shuffleCellSize":"(.*?)"', captchaResponseHtml)
shuffleCellSize = reMatch.group(1) if reMatch else None
captcha_data={
"token":token,
"line":1,
"challengeBaseUrl":challengeBaseUrl,
"requestId":requestId,
"requestToken":requestToken,
"shuffleSeed":shuffleSeed,
"shuffleCellSize":shuffleCellSize,
"proxy":proxy,
}
captcha_data=json.dumps(captcha_data)
response = requests.post(nucaptcha_api, data=captcha_data)
if response.status_code != 200:
print({"error": "api error", "status_code": response.status_code, "response": response.text})
sys.exit()
response_data = response.json()
if response_data['code']!=200:
print(response.text)
sys.exit()
captcha_answer=response_data["data"]["nucaptcha-answer"]
captcha_token=response_data["data"]["nucaptcha-token"]
post_data='{"userAgent":"'+ua+'","stplSessionId":"93ec842ae7ef1c6ee47b26591a23828b","placement":"Login","page":1,"requestUrl":"https://www.staples.com/idm/com/login","ndsModeValue":"","captchaAnswer":"'+captcha_answer+'","nuCaptchaToken":"'+captcha_token+'","rememberMe":true,"username":"[email protected]","password":"123123123"}'
response_data = tls_result("https://www.staples.com/idm/api/identityProxy/logincommon", "POST", headers, post_data, user_agent, proxy, cookie_str);
response_html = response_data["data"]["result"]
if "access_token" in response_html:
print(f'login successfully!')
else:
print("Login failed, "+response_html)
else:
print(f'Failed to get data! {response_html}')